Sunday, September 11, 2011

Quiz of the day | OCPJP (6)

Given:

interface Beautiful { public void makeUp(); }

Which will compile? (Choose all that apply.)

A. public class Girl implements Beautiful { public void makeUp() { } }

B. public class Girl implements Beautiful { public void makeUp(int x) { } }

C. public class Girl implements Beautiful {
public void makeUp() { System.out.println("The girl is beautiful..."); }
}
D. public abstract class Girl implements Beautiful {
public void makeUp(int x) { }
}
E. public abstract class Girl implements Beautiful {
public void makeUp(int x) ;
}


DOWNLOAD the answer

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