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

  1. Which are true about this code? (Choose all that apply.)

var blocky = “””

squirrel \s

pigeon \

termite”””;

System.out.print(blocky);

  1. It outputs two lines.
  • It outputs three lines.
  • It outputs four lines.
  • There is one line with trailing whitespace.
  • There are two lines with trailing whitespace.
  • If we indented each line five characters, it would change the output.
  1. What lines are printed by the following program? (Choose all that apply.)
  1. public class WaterBottle {
  • private String brand;
  • private boolean empty;
  • public static float code;
  • public static void main(String[] args) {
  • WaterBottle wb = new WaterBottle();
  • System.out.println(“Empty = ” + wb.empty);
  • System.out.println(“Brand = ” + wb.brand);
  • System.out.println(“Code = ” + code);
  1. } }
  1. Line 8 generates a compiler error.
  • Line 9 generates a compiler error.
  • Empty =
  • Empty = false
  • Brand =
  • Brand = null
  • Code = 0.0
  • Code = 0f
  1. Which of the following statements about var are true? (Choose all that apply.)
  1. A var can be used as a constructor parameter.
  • The type of a var is known at compile time.
  • A var cannot be used as an instance variable.
  • A var can be used in a multiple variable assignment statement.
  • The value of a var cannot change at runtime.
  • The type of a var cannot change at runtime.
  • The word var is a reserved word in Java.
  1. Which are true about the following code? (Choose all that apply.)

var num1 = Long.parseLong(“100”); var num2 = Long.valueOf(“100”); System.out.println(Long.max(num1, num2));

  1. The output is 100.
  • The output is 200.
  • The code does not compile.
  • num1 is a primitive.
  • num2 is a primitive.
  • Which statements about the following class are correct? (Choose all that apply.)
  1. public class PoliceBox {
  • String color;
  • long age;
  • public void PoliceBox() {
  • color = “blue”;
  • age = 1200;
  • }
  • public static void main(String []time) {
  • var p = new PoliceBox();
  1. var q = new PoliceBox();
  1. p.color = “green”;
  1. p.age = 1400;
  1. p = q;
  1. System.out.println(“Q1=”+q.color);
  1. System.out.println(“Q2=”+q.age);
  1. System.out.println(“P1=”+p.color);
  1. System.out.println(“P2=”+p.age);
  1. } }
  1. It prints Q1=blue.
  • It prints Q2=1200.
  • It prints P1=null.
  • It prints P2=1400.
  • Line 4 does not compile.
  • Line 12 does not compile.
  • Line 13 does not compile.
  • None of the above.
  • What is the output of executing the following class?
  1. public class Salmon {
  • int count;
  • { System.out.print(count+”-­”); }
  • { count++; }
  • public Salmon() {
  • count = 4;
  • System.out.print(2+”-­”);
  • }
  • public static void main(String[] args) {
  1. System.out.print(7+”-­”);
  1. var s = new Salmon();
  1. System.out.print(s.count+”-­”); } }
  1. 7-0-2-1-
  • 7-0-1-
  • 0-7-2-1-
  • 7-0-2-4-
  • 0-7-1-
  • The class does not compile because of line 3.
  • The class does not compile because of line 4.
  • None of the above.
  • Given the following class, which of the following lines of code can independently replace INSERT CODE HERE to make the code compile? (Choose all that apply.)

public class Price {

public void admission() {

INSERT CODE HERE

System.out.print(amount);

} }

  1. int Amount = 0b11;
  • int amount = 9L;
  • int amount = 0xE;
  • int amount = 1_2.0;
  • double amount = 1_0_.0;
  • int amount = 0b101;
  • double amount = 9_2.1_2;
  • double amount = 1_2_.0_0;
  • Which statements about the following class are true? (Choose all that apply.)
  1. public class River {
  • int Depth = 1;
  • float temp = 50.0;
  • public void flow() {
  • for (int i = 0; i < 1; i++) {
  • int depth = 2;
  • depth++;
  • temp-­-­;
  • }
  1. System.out.println(depth);
  1. System.out.println(temp); }
  1. public static void main(String… s) {
  1. new River().flow();
  1. } }
  1. Line 3 generates a compiler error.
  • Line 6 generates a compiler error.
  • Line 7 generates a compiler error.
  • Line 10 generates a compiler error.
  • The program prints 3 on line 10.
  • The program prints 4 on line 10.
  • The program prints 50.0 on line 11.
  • The program prints 49.0 on line 11.