- Which are true about this code? (Choose all that apply.)
var blocky = “””
squirrel \s
pigeon \
termite”””;
System.out.print(blocky);
- It outputs two 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.
- What lines are printed by the following program? (Choose all that apply.)
- public class WaterBottle {
- 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);
- } }
- Line 8 generates a compiler error.
- Line 9 generates a compiler error.
- Which of the following statements about var are true? (Choose all that apply.)
- 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.
- 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));
- The output is 100.
- The code does not compile.
- Which statements about the following class are correct? (Choose all that apply.)
- public class PoliceBox {
- public void PoliceBox() {
- public static void main(String []time) {
- var q = new PoliceBox();
- p.color = “green”;
- p.age = 1400;
- p = q;
- System.out.println(“Q1=”+q.color);
- System.out.println(“Q2=”+q.age);
- System.out.println(“P1=”+p.color);
- System.out.println(“P2=”+p.age);
- } }
- It prints Q1=blue.
- Line 12 does not compile.
- Line 13 does not compile.
- What is the output of executing the following class?
- public class Salmon {
- { System.out.print(count+”-”); }
- System.out.print(2+”-”);
- public static void main(String[] args) {
- System.out.print(7+”-”);
- var s = new Salmon();
- System.out.print(s.count+”-”); } }
- 7-0-2-1-
- The class does not compile because of line 3.
- The class does not compile because of line 4.
- 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);
} }
- int Amount = 0b11;
- double amount = 1_2_.0_0;
- Which statements about the following class are true? (Choose all that apply.)
- public class River {
- for (int i = 0; i < 1; i++) {
- System.out.println(depth);
- System.out.println(temp); }
- public static void main(String… s) {
- new River().flow();
- } }
- 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.