Final Exam (page 2 of 3) PDF

Title Final Exam (page 2 of 3)
Author Anas Saker
Course Programming 1
Institution University of the People
Pages 9
File Size 211.2 KB
File Type PDF
Total Downloads 91
Total Views 162

Summary

Final Exam Part 2...


Description

Anas Haj Sakor

Home  My courses  CS 1102 - AY2021-T4  Final Exam (Days 1 - 4)  Final Exam

Question 11

Not yet answered

Marked out of 1.00

Consider the following Java program. 1 public class HelloWorld { 2

// My first program!

3

public static void main(String[] args) {

4

System.out.println("Hello, World!");

5

}

6 } What starts on line 1? Select one: a. a statement b. a package c. a method definition d. a comment e. a class definition Clear my choice



Question 12

Not yet answered

Marked out of 1.00

In a for loop, how many times does the continuation condition run? Select one: a. Zero or more times, at the beginning of each iteration. b. Zero or more times, at the end of each iteration. c. At least once, at the beginning of each iteration. d. At least once, at the end of each iteration. e. Exactly once. Clear my choice



Question 13

Not yet answered

Marked out of 1.00

Consider the following Java program.Which one of the following best describes "setFlavor"?

public class Food { static int count; private String flavor = "sweet"; Food() { count++; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food(); System.out.println(pepper.getFlavor()); } } Select one: a. a class method b. a getter method c. a setter method d. a public method e. a static method Clear my choice



Question 14

Not yet answered

Marked out of 1.00

Which one of the following does NOT describe an array? Select one: a. Its elements can be a primitive type. b. The number of its elements can change. c. It can be used in a for-each loop. d. It has a numbered sequence of elements. e. It provides efficient random access to its elements. Clear my choice



Question 15

Not yet answered

Marked out of 1.00

What is the output of the following Java program?

public class Food { static int count; private String flavor = "sweet"; Food(String s) { flavor = s; } void setFlavor(String s) { flavor = s; } String getFlavor() { return flavor; } static public void main(String[] args) { Food pepper = new Food("spicy"); Food chile = pepper; pepper.setFlavor("smoky"); System.out.println(chile.getFlavor()); } } Select one: a. false b. smoky c. spicy d. sweet e. true Clear my choice



Question 16

Not yet answered

Marked out of 1.00

Which of the following can a class NOT be used for? Select one: a. a primitive type b. a container for static methods c. a container for static variables d. a type for method parameters e. a type for variables Clear my choice



Question 17

Not yet answered

Marked out of 1.00

What is the output of the following Java program?

class Food { Food() { printFlavor(); } void printFlavor() { System.out.println("bland"); } } class Pepper extends Food { void printFlavor() { System.out.println("spicy"); } } public class Lunch { public static void main(String[] args) { Food lunch = new Pepper(); } } Select one: a. bland b. bland spicy c. (no output) d. spicy e. spicy bland Clear my choice



Question 18

Not yet answered

Marked out of 1.00

Consider the following Java method.

public static void main(String[] args) { System.out.println("Hello, Final!"); } Which term best describes "void"? Select one: a. actual parameter or argument b. formal parameter c. modifier d. return type e. superclass Clear my choice

Question 19

Not yet answered

Marked out of 1.00

Which of the following is NOT an effective strategy when your program does not work? Select one: a. Make random changes to code that you do not understand until it accidentally works. b. Read through your code and figure out what it does step by step. c. Check each error message generated by the compiler or IDE. d. Add debugging statements to output information about the state of your program while it runs. e. Use a debugger to pause your program while it is running so you can check its state. Clear my choice



Question 20

Not yet answered

Marked out of 1.00

In a for loop, how many times does the update run? Select one: a. Zero or more times, at the beginning of each iteration. b. Zero or more times, at the end of each iteration. c. At least once, at the beginning of each iteration. d. At least once, at the end of each iteration. e. Exactly once. Clear my choice

◄ Review Quiz Jump to...

...


Similar Free PDFs