| 3.10 | Which statements are true? Select the three correct answers. -
The result of the expression (1 + 2 + "3") would be the string "33" . -
The result of the expression ("1" + 2 + 3) would be the string "15" . -
The result of the expression (4 + 1.0f) would be the float value 5.0f . -
The result of the expression (10/9) would be the int value 1 . -
The result of the expression ('a' + 1) would be the char value 'b' . |
| 3.11 | What happens when you try to compile and run the following program? public class Prog1 { public static void main(String[] args) { int k = 1; int i = ++k + k++ + + k; System.out.println(i); } } Select the one correct answer. -
The program will not compile. The compiler will complain about the expression ++k + k++ + + k . -
The program will compile and will print the value 3 when run. -
The program will compile and will print the value 4 when run. -
The program will compile and will print the value 7 when run. -
The program will compile and will print the value 8 when run. |
| 3.12 | Which is the first incorrect line that will cause a compile time error in the following program? public class MyClass { public static void main(String[] args) { char c; int i; c = 'a'; // (1) i = c; // (2) i++; // (3) c = i; // (4) c++; // (5) } } Select the one correct answer. -
The line labeled (1) -
The line labeled (2) -
The line labeled (3) -
The line labeled (4) -
The line labeled (5) -
None of the lines are incorrect. The program will compile just fine. |
| 3.13 | What happens when you try to compile and run the following program? public class Cast { public static void main(String[] args) { byte b = 128; int i = b; System.out.println(i); } } Select the one correct answer. -
The compiler will refuse to compile it, since you cannot assign a byte to an int without a cast. -
The program will compile and will print 128 when run. -
The compiler will refuse to compile it, since 128 is outside the legal range of values for a byte . -
The program will compile, but will throw a ClassCastException when run. -
The program will compile and will print 255 when run. |
| 3.14 | What will the following program print when run? public class EvaluationOrder { public static void main(String[] args) { int[] array = { 4, 8, 16 }; int i=1; array[++i] = --i; System.out.println(array[0] + array[1] + array[2]); } } Select the one correct answer. -
13 -
14 -
20 -
21 -
24 |