Question 1
class JSC201 { static byte m1() {final char c1 = '\u0001';
return c1; // 1
}
static byte m2(final char c2) {return c2;} // 2 public static void main(String[] args) {char c3 = '\u0003';
System.out.print(""+m1()+m2(c3)); // 3}}
What is the result of attempting to compile and run the program?
| a. | Prints: 13 |
| b. | Prints: 4 |
| c. | Compile-time error at 1 |
| d. | Compile-time error at 2 |
| e. | Run-time error |
| f. | None of the above |
Question 2
Which of the follow are true statements.
class A { public static void main (String[] args) {Error error = new Error();
Exception exception = new Exception();
System.out.print((exception instanceof Throwable) + ",");
System.out.print(error instanceof Throwable);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
Question 4
class B {private String name;
public B(String s) {name = s;} protected void finalize() {System.out.print(name);}}
class E { public static void m() { B x1 = new B("X"), y1 = new B("Y");}
public static void main(String[] args) {m(); System.gc();
}}
Which of the following could not be a result of attempting to compile and run the program?
| a. | Prints: XY |
| b. | Prints: YX |
| c. | Prints: XXYY |
| d. | Nothing is printed. |
| e. | None of the above |
Question 5
class JJF1 { public static void main (String args[]) {System.out.print(Byte.MIN_VALUE+",");
System.out.print(Byte.MAX_VALUE);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,255 |
| b. | Prints: 0,256 |
| c. | Prints: -127,128 |
| d. | Prints: -128,127 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
Question 6
class GRC1 {public static void main(String[] args) {}} // 1class GRC2 {protected static void main(String[] args) {}} // 2class GRC3 {private static void main(String[] args) {}} // 3
What is the result of attempting to compile each of the three class declarations and invoke each main method from the command line?
| a. | Compile-time error at line 1. |
| b. | Compile-time error at line 2. |
| c. | Compile-time error at line 3. |
| d. | An attempt to run GRC1 from the command line fails. |
| e. | An attempt to run GRC2 from the command line fails. |
| f. | An attempt to run GRC3 from the command line fails. |
Question 7
class EBH201 { public static void main (String[] args) {int a = 1 || 2 ^ 3 && 5;
int b = ((1 || 2) ^ 3) && 5;
int c = 1 || (2 ^ (3 && 5));
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0,0 |
| b. | Prints: 0,0,3 |
| c. | Prints: 0,3,0 |
| d. | Prints: 0,3,3 |
| e. | Prints: 3,0,0 |
| f. | Prints: 3,0,3 |
| g. | Prints: 3,3,0 |
| h. | Prints: 3,3,3 |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
Question 8
class GFC100 { public static void main(String[] args) {final short s1 = 1; // 1
final char c1 = 1; // 2
byte b1 = s1; // 3
byte b2 = c1; // 4
byte b3 = 1; // 5
byte b4 = 1L; // 6
byte b5 = 1.0; // 7
byte b6 = 1.0d; // 8
}}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | 6 |
| g. | 7 |
| h. | 8 |
Question 8
class A { void m1(int i) {int j = i % 3;
switch (j) { case 0: System.out.print("0"); break; case 1: System.out.print("1"); break;default:
assert j == 2;
System.out.print(j);
}}
public static void main (String[] args) {A a = new A();
for (int i=5; i >= -1; i--) {a.m1(i);}}}
Question 9
Which statements are true?
| a. | With assertions enabled it prints 210210-1 followed by an AssertionError message. |
| b. | With assertions enabled it prints 210210 followed by an AssertionError message. |
| c. | With assertions enabled it prints only 210210. |
| d. | With assertions enabled it prints nothing. |
| e. | With assertions disabled it prints 210210-1 |
| f. | With assertions disabled it prints only 210210 |
| g. | Assertions should not be used within the default case of a switch statement. |
Question 10
Which of these words belong to the set of Java keywords?
| a. | transient |
| b. | serializable |
| c. | runnable |
| d. | run |
| e. | volatile |
| f. | externalizable |
| g. | cloneable |
Question 11
class JMM101 { public static void main(String[] args) {int i = 0;
while (i++ < args.length) {System.out.print(args[i]);
}}}
java JMM101 A B C D E F
What is the result of attempting to compile and run the program using the specified command line?
| a. | Prints: JMM101ABCDEF |
| b. | Prints: ABCDEF |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |