Review Questions
The answers to the chapter review questions can be found in the Appendix.
- Which of the following are legal entry point methods that can be run from the command line? (Choose all that apply.)
- private static void main(String[] args)
- public static final main(String[] args)
- public void main(String[] args)
- public static final void main(String[] args)
- public static void main(String[] args)
- public static main(String[] args)
- Which answer options represent the order in which the following statements can be assem-bled into a program that will compile successfully? (Choose all that apply.)
- X,Y,Z
- Which of the following are true? (Choose all that apply.)
public class Bunny {
public static void main(String[] x) {
Bunny bun = new Bunny();
} }
- Bunny is a class.
- Bunny is a reference to an object.
- bun is a reference to an object.
- main is a reference to an object.
- The main() method doesn’t run because the parameter name is incorrect.
- Which of the following are valid Java identifiers? (Choose all that apply.)
- _
- Which statements about the following program are correct? (Choose all that apply.)
- private void roar(Bear b) {
- System.out.println(“Roar!”);
- public static void main(String[] args) {
- Bear brownBear = new Bear();
- Bear polarBear = new Bear();
- brownBear.roar(polarBear);
- polarBear = null;
- brownBear = null;
- System.gc(); } }
- The object created on line 9 is eligible for garbage collection after line 13.
- The object created on line 9 is eligible for garbage collection after line 14.
- The object created on line 10 is eligible for garbage collection after line 12.
- The object created on line 10 is eligible for garbage collection after line 13.
- Garbage collection is guaranteed to run.
- Garbage collection might or might not run.
- The code does not compile.
- Assuming the following class compiles, how many variables defined in the class or method are in scope on the line marked on line 14?
- public class Camel {
- public void spit(float distance) {
- { double teeth = 32 + distance++; }
- int age = twoHumps ? 1 : 2;
- short i=-1;
- for(i=0; i<10; i++) {
- var Private = 2;
- }
- // SCOPE
- }
- }
- }
- 2
- Which are true about this code? (Choose all that apply.)
public class KitchenSink {
private int numForks;
public static void main(String[] args) {
int numKnives;
System.out.print(“””
“# forks = ” + numForks +
- # knives = ” + numKnives +
}
}
- The output includes: # forks = 0.
- The output includes: # knives = 0.
- The output includes: # cups = 0.
- The output includes a blank line.
- The output includes one or more lines that begin with whitespace.
- The code does not compile.