class EBH019 {
public static void main (String args[]) {
int i1 = 0xffffffff, i2 = i1 << 1;
int i3 = i1 >> 1, i4 = i1 >>> 1;
System.out.print(Integer.toHexString(i2) + ",");
System.out.print(Integer.toHexString(i3) + ",");
System.out.print(Integer.toHexString(i4));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: ffffffff,ffffffff,ffffffff |
| b. | Prints: ffffffff,ffffffff,7fffffff |
| c. | Prints: ffffffff,7fffffff,ffffffff |
| d. | Prints: ffffffff,7ffffffe,7ffffffe |
| e. | Prints: fffffffe,ffffffff,ffffffff |
| f. | Prints: fffffffe,ffffffff,7fffffff |
| g. | Prints: fffffffe,7fffffff,ffffffff |
| h. | Prints: fffffffe,7fffffff,7fffffff |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class Black {
public static void main(String[] args) {
short s1 = 1; //1
char c1 = 1; //2
byte b1 = s1; //3
byte b2 = c1; //4
final short s2 = 1; //5
final char c2 = 1; //6
byte b3 = s2; //7
byte b4 = c2; //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 |
class EBH013 {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((~x == -x - 1)+","+(~y == -y - 1));
}}
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. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH014 {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((y % x) + ",");
System.out.print(y == ((y/x)*x + (y%x)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1,true |
| b. | Prints: 2,true |
| c. | Prints: 1,false |
| d. | Prints: 2,false |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class Color {}
class Red extends Color {}
class Blue extends Color {}
class A {
public static void main (String[] args) {
Color color1 = new Red(); Red color2 = new Red();
boolean b1 = color1 instanceof Color;
boolean b2 = color1 instanceof Blue;
boolean b3 = color2 instanceof Blue;
System.out.print(b1+","+b2+","+b3);
}}
What is the result of attempting to compile and run the program?
| a. | false,false,false |
| b. | false,false,true |
| c. | false,true,false |
| d. | false,true,true |
| e. | true,false,false |
| f. | true,false,true |
| g. | true,true,false |
| h. | true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH020 {
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 |
class EBH025 {
public static void main (String args[]) {
int i1 = 0xffffffff, i2 = i1 << 33;
int i3 = i1 << (33 & 0x1f);
System.out.print(Integer.toHexString(i2) + ",");
System.out.print(Integer.toHexString(i3));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0 |
| b. | Prints: 0,fffffffe |
| c. | Prints: 0,ffffffff |
| d. | Prints: ffffffff,ffffffff |
| e. | Prints: ffffffff,fffffffe |
| f. | Prints: fffffffe,ffffffff |
| g. | Prints: fffffffe,fffffffe |
| h. | Run-time error |
| i. | Compile-time error |
| j. | None of the above |
class GFC205 {}
class GFC206 extends GFC205 {}
class GFC207 extends GFC206 {
static void m(GFC205 x, GFC205 y) {System.out.print("GFC205,GFC205");}
static void m(GFC205 x, GFC206 y) {System.out.print("GFC205,GFC206");}
static void m(GFC206 x, GFC205 y) {System.out.print("GFC206,GFC205");}
static void m(GFC206 x, GFC206 y) {System.out.print("GFC206,GFC206");}
public static void main(String[] args) {
GFC207 gfc207 = new GFC207();
m(gfc207, gfc207);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: GFC205,GFC205 |
| b. | Prints: GFC205,GFC206 |
| c. | Prints: GFC206,GFC205 |
| d. | Prints: GFC206,GFC206 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class GFC211 {}
class GFC212 extends GFC211 {}
class GFC213 extends GFC212 {
static void m(GFC211 x, GFC211 y) {System.out.print("GFC211,GFC211");}
static void m(GFC211 x, GFC212 y) {System.out.print("GFC211,GFC212");}
static void m(GFC212 x, GFC211 y) {System.out.print("GFC212,GFC211");}
static void m(GFC212 x, GFC212 y) {System.out.print("GFC212,GFC212");}
static void m(GFC211 x, GFC213 y) {System.out.print("GFC211,GFC213");}
public static void main(String[] args) {
GFC213 gfc213 = new GFC213();
m(gfc213, gfc213);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: GFC211,GFC211 |
| b. | Prints: GFC211,GFC212 |
| c. | Prints: GFC212,GFC211 |
| d. | Prints: GFC212,GFC212 |
| e. | Prints: GFC211,GFC213 |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class EBH015 {
public static void main (String[] args) {
System.out.print((new Object() instanceof Object)+",");
System.out.print((new Object() instanceof String)+",");
System.out.print((new String() instanceof Object));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class GFC214 {
static void m1(boolean b1) {System.out.print("boolean ");}
static void m1(byte b1) {System.out.print("byte ");}
static void m1(short s1) {System.out.print("short ");}
static void m1(char c1) {System.out.print("char ");}
static void m1(int i1) {System.out.print("int ");}
public static void main(String[] args) {
byte b1; m1(b1 = 1); m1(b1); m1(b1 == 1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: byte byte byte |
| b. | Prints: byte byte boolean |
| c. | Prints: int int int |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class GFC308 {
int[] i1 = {1}, i2 = {3};
void m1() {
m2(i1, i2);
System.out.print(i1[0] + "," + i2[0]);
}
void m2(int[] i1, int[] i2) {
int[] i3 = i1;
this.i1 = i2;
this.i2 = i3;
}
public static void main (String[] args) {
new GFC308().m1();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0 |
| b. | Prints: 1,1 |
| c. | Prints: 1,3 |
| d. | Prints: 3,1 |
| e. | Prints: null,null |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class EBH108 {
public static void main(String s[]) {
int i=0;
int j = ++i + ((++i * ++i) % ++i) + ++i;
System.out.print(j%5);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1 |
| b. | Prints: 2 |
| c. | Prints: 3 |
| d. | Prints: 4 |
| e. | Prints: 5 |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class A {}
class B extends A {}
class C extends B {
static void m(A x, A y) {System.out.print("AA");}
static void m(A x, B y) {System.out.print("AB");}
static void m(B x, A y) {System.out.print("BA");}
static void m(B x, B y) {System.out.print("BB");}
public static void main(String[] args) {
A a1; B b1;
m(null,null); m(a1=null,b1=null); m(b1, a1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: BBABAB |
| b. | Prints: BBABBA |
| c. | Prints: BBBBAB |
| d. | Prints: BBBBBA |
| e. | Prints: BBBBBB |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class A {}
class B extends A {}
class C extends B {
static void m1(A x) {System.out.print("m1A");}
static void m2(B x) {System.out.print("m2B"); m1(x);}
static void m2(A x) {System.out.print("m2A"); m1(x);}
static void m3(C x) {System.out.print("m3C"); m2(x);}
static void m3(B x) {System.out.print("m3B"); m2(x);}
static void m3(A x) {System.out.print("m3A"); m2(x);}
public static void main(String[] args) {
m3(new C());
}}
What is the result of attempting to compile and run the program?
| a. | Prints: m3Am2Am1A |
| b. | Prints: m3Bm2Bm1A |
| c. | Prints: m3Cm2Bm1A |
| d. | Prints: m3Cm2Am1A |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class EBH023 {
static String m1(boolean b){return b?"T":"F";}
public static void main(String [] args) {
boolean b1 = false?false:true?false:true?false:true;
boolean b2 = false?false:(true?false:(true?false:true));
boolean b3 = ((false?false:true)?false:true)?false:true;
System.out.println(m1(b1) + m1(b2) + m1(b3));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: FFF |
| b. | Prints: FFT |
| c. | Prints: FTF |
| d. | Prints: FTT |
| e. | Prints: TFF |
| f. | Prints: TFT |
| g. | Prints: TTF |
| h. | Prints: TTT |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH024 {
public static void main(String[] args) {
int i1 = 15;
String b1 = (i1>30)?"Red":(i1>20)?"Green":(i1>10)?"Blue":"Violet";
String b2 = (i1>30)?"Red":((i1>20)?"Green":((i1>10)?"Blue":"Violet"));
System.out.println(b1 + "," + b2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: Red,Red |
| b. | Prints: Green,Green |
| c. | Prints: Blue,Blue |
| d. | Prints: Violet,Violet |
| e. | Prints: Blue,Violet |
| f. | Prints: Violet,Blue |
| g. | Prints: Blue,Green |
| h. | Prints: Green,Blue |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH021 {
public static void main(String[] args) {
System.out.print((-1 & 0x1f) + "," + (8 << -1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0 |
| b. | Prints: -1,4 |
| c. | Prints: 0x1f,8 |
| d. | Prints: 31,16 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |