Monday, September 26, 2011

Quiz of the day | OCPJP (21)

Given:

3. public class Sep26 {
4. public static void main(String[] args) {
5. short f4 = 4;
6. new Sep26().go(f4);
7. new Sep26().go(new Integer(8));
8. }
9. void go(Short s) { System.out.print("S "); }
10. void go(Long l) { System.out.print("L "); }
11. void go(int i) { System.out.print("i "); }
12. void go(Number n) { System.out.print("N "); }
13. }

What is the result?

A. i L
B. i N
C. S L
D. S N
E. Compilation fails.
F. An exception is thrown at runtime.


DOWNLOAD the answer

Sunday, September 25, 2011

Quiz of the day | OCPJP (20)

Given:

2. public class X {
3. private int g = 3;
4. public static void main(String[] args) {
5. new X().xii();
6. }
7. void xii() {
8. int x = 6;
9. Y y = new Y();
10. class Y {
11. void yii() { System.out.println(g + x); }
12. }
13. y.yii();
14. }
15. }

What is the result? (Choose all that apply.)

A. Compilation succeeds.
B. Compilation fails due to an error on line 3.
C. Compilation fails due to an error on line 8.
D. Compilation fails due to an error on line 9.
E. Compilation fails due to an error on line 10.
F. Compilation fails due to accessing x on line 11.
G. Compilation fails due to accessing y on line 11.


DOWNLOAD the answer

Saturday, September 24, 2011

Quiz of the day | OCPJP (19)

Given:

3. public class O {
4. private int a = 2;
5. protected int s = 3;
6. private static int d = 4;
7. protected static int f = 5;
8. public static void main(String[] args) {
9. int a = 6; int s = 7;
10. int d = 8; int f = 9;
11. new O().new P().p();
12. }
13. class P {
14. void p() { System.out.println(a + " " + s + " " + d + " " + f); }
15. } }

What is the result?

A. 2 3 4 5
B. 2 7 4 9
C. 6 3 8 4
D. 6 7 8 9
E. Compilation fails due to multiple errors.
F. Compilation fails due only to an error on line 11.
G. Compilation fails due only to an error on line 14.


DOWNLOAD the answer

Friday, September 23, 2011

Quiz of the day | OCPJP (18)

Given:

2. interface A { void a(); }
3. // insert code here

Which code, inserted independently at line 3, will compile? (Choose

all that apply.)

A. interface B extends A { }
B. interface B extends A { void a(); }
C. interface B extends A { void doA(); }
D. interface B extends A { void a() { ; } }
E. interface B extends A { protected void a(); }
F. interface B extends A { void a(); void doA(); }


DOWNLOAD the answer

Thursday, September 22, 2011

Quiz of the day | OCPJP (17)

Which are valid command-line switches when working with assertions? (Choose all that apply.)

A. -ea
B. -da
C. -dsa
D. -eva
E. -enableassertions


DOWNLOAD the answer