Review Questions – Building Blocks – 1Z0-829 Study Guide

Review Questions

The answers to the chapter review questions can be found in the Appendix.

  1. Which of the following are legal entry point methods that can be run from the command line? (Choose all that apply.)
  1. 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.)
  • class Rabbit {}
  • import java.util.*;
  • package animals;
  1. X,Y,Z
  • Y,Z,X
  • Z,Y,X
  • Y, X
  • Z, X
  • X, Z
  • None of the above
  • Which of the following are true? (Choose all that apply.)

public class Bunny {

public static void main(String[] x) {

Bunny bun = new Bunny();

} }

  1. Bunny is a class.
  • bun is a class.
  • main 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.)
  1. _
  • _helloWorld$
  • true
  • java.lang
  • Public
  • 1980_s
  • _Q2_
  • Which statements about the following program are correct? (Choose all that apply.)
  • public class Bear {
  • private Bear pandaBear;
  • private void roar(Bear b) {
  • System.out.println(“Roar!”);
  • pandaBear = b;
  • }
  • public static void main(String[] args) {
  • Bear brownBear = new Bear();
  1. Bear polarBear = new Bear();
  1. brownBear.roar(polarBear);
  1. polarBear = null;
  1. brownBear = null;
  1. System.gc(); } }
  1. 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?
  1. public class Camel {
  • { int hairs = 3_000_0; }
  • long water, air=2;
  • boolean twoHumps = true;
  • public void spit(float distance) {
  • var path = “”;
  • { double teeth = 32 + distance++; }
  • while(water > 0) {
  • int age = twoHumps ? 1 : 2;
  1. short i=-­1;
  1. for(i=0; i<10; i++) {
  1. var Private = 2;
  1. }
  1. // SCOPE
  1. }
  1. }
  1. }
  1. 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • None of the above
  • 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 +
  • cups = 0″””);

}

}

  1. 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.