Friday, September 16, 2011

Quiz of the day | OCPJP (11)

3. class P {
4. P play() { System.out.print("p "); return new P(); }
5. P play(int x) { System.out.print("p x "); return new P(); }
6. }
7. class Q extends P {
8. Q play() { System.out.print("q "); return new Q(); }
9. P play(int x) { System.out.print("r "); return new P(); }
10.
11. public static void main(String[] args) {
12. new Q().play();
13. new Q().play(7);
14. super.play(7);
15. new P().play();
16. P s = new Q();
17. s.play();
18. } }

What is the result?

A. q r r p p
B. q r p x p r
C. q r p x p q
D. Compilation fails due to a single error.
E. Compilation fails due to errors on more than one line.


DOWNLOAD the answer

0 comments: