Saturday, September 10, 2011

Quiz of the day | OCPJP (5)

Given:

class Ca { }
class Cb { }
interface Ia { }
interface Ib { }
class Aa extends Cb implements Ia { }
class Ab implements Ia implements Ib { }
class Ba implements Ca { }
class Bb extends Ca, implements Ib { }
class Ca extends Ia, Ib { }
class Cb implements Ia, Ib { }

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

A. Class Aa does not compile.
B. Class Ab does not compile.
C. Class Ba does not compile.
D. Class Bb does not compile.
E. Class Ca does not compile.
F. Class Cb does not compile.
G. Compilation succeeds for all of the classes.


DOWNLOAD the answer

Friday, September 9, 2011

Quiz of the day | OCPJP (4)

Given:

2. class A { }
3. public class B extends A {
4. public static void main(String[] args) {
5. A a = new A();
6. B b = new B();
7. // insert code here
8. }
9. }

Which, inserted independently at line 7, compile? (Choose all that apply.)

A. if(b instanceof a) System.out.print("a ");
B. if(b.instanceof(a)) System.out.print("b ");
C. if(b instanceof A) System.out.print("c ");
D. if(b instanceOf A) System.out.print("d ");
E. if(b.instanceof(A)) System.out.print("e ");


DOWNLOAD the answer

Thursday, September 8, 2011

Quiz of the day | OCPJP (3)

2. public class P {
3. private int p = 1;
4. public static void main(String[] args) {
5. protected int p = 3;
6. new P().new Q().q();
7. }
8. class Q {
9. void q() { System.out.println("number " + p); }
10. }
11. }

Which are true? (Choose all that apply.)
A. Compilation succeeds.
B. The output is "number 1".
C. The output is "number 3".
D. Compilation fails due to an error on line 5.
E. Compilation fails due to an error on line 6.
F. Compilation fails due to an error on line 9.


DOWNLOAD the answer

Wednesday, September 7, 2011

Quiz of the day | OCPJP (2)

Given:

2. public class X {
3. public static void main(String[] args) {
4. String result = "";
5. int x = 4, y = 5;
6. if(x == 0) { result += "5"; }
7. else if (x > 6) { result += "6"; }
8. else if (y < 6) { result += "7"; }
9. else if (x == 4) { result += "8"; }
10. else { result += "9"; }
11. System.out.println(result);
12. }
13. }

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

A. 789
B. 7
C. 78
D. 79
E. Compilation fails due to an error on line 5.
F. Compilation fails due to errors on lines 8 and 9.
G. Compilation fails due to errors on lines 7, 8, and 9.


DOWNLOAD the answer

Tuesday, September 6, 2011

Quiz of the day | OCPJP (1)

Given:

public class A extends B {
A() {
System.out.println("a ");
}
public static void main(String[] args) {
new A();
}
}
class B extends C {
B() {
System.out.print("b ");
}
private B(String b) {
}
}
abstract class C {
C() {
System.out.print("c ");
}
}

What is the result?

A. a
B. a b
C. b a
D. a b c
E. c b a
F. Compilation fails due to a single error in the code.
G. Compilation fails due to multiple errors in the code.

DOWNLOAD the answer