Friday, September 30, 2011

Quiz of the day | OCPJP (25)

Which is true? (Choose all that apply.)

A. "C extends I" is correct if and only if C is a class and I is an interface
B. "C extends I" is correct if and only if C is an interface and I is a class
C. "C extends I" is correct if C and I are either both classes or both interfaces
D. "C extends I" is correct for all combinations of C and I being classes and/or interfaces


DOWNLOAD the answer

Thursday, September 29, 2011

Quiz of the day | OCPJP (24)

3. public class J {
4. public static void main(String[] args) {
5. int j = 7;
6. assert(++j > 7);
7. assert(++j > 8): "Jakarta";
8. assert(j > 10): j=12;
9. assert(j==12): macet();
10. assert(j==12): new J();
11. }
12. static void macet() { }
13. }

Which are true? (Choose all that apply.)

A. Compilation succeeds
B. Compilation fails due to an error on line 6
C. Compilation fails due to an error on line 7
D. Compilation fails due to an error on line 8
E. Compilation fails due to an error on line 9
F. Compilation fails due to an error on line 10


DOWNLOAD the answer

Wednesday, September 28, 2011

Quiz of the day | OCPJP (23)

Given:

3. class A {
4. public void a() { System.out.print("A "); }
5. }
6. class B extends A {
7. public void b() { System.out.print("B "); }
8. public void a() { System.out.print("a "); }
9. }
10. public class C {
11. public static void main(String[] args) { new C().c(); }
12. void c() {
13. new B().a();
14. ((A) new B()).a();
15. ((A) new B()).b();
16. }
17. }

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

A. a a B
B. a A B
C. a a followed by an exception
D. a A followed by an exception
E. Compilation fails with an error at line 14
F. Compilation fails with an error at line 15

DOWNLOAD the answer

Tuesday, September 27, 2011

Quiz of the day | OCPJP (22)

Given:

1. enum Menu {HOME, ABOUT, CONTACT};
2. public class Main {
3. public static void main(String[] args) {
4. Main m = new Main();
5. Menu[] v = Menu.values();
6. v = Menu.getValues();
7. for(Menu me: Menu.values()) m.getEnum(me);
8. for(int x = 0; x < Menu.values().length; x++) m.getEnum(v[x]);
9. for(int x = 0; x < Menu.length; x++) m.getEnum(v[x]);
10. for(Menu me: v) m.getEnum(me);
11. }
12. public void getEnum(Menu e) {
13. System.out.print(e + " ");
14. } }


Which line(s) of code will cause a compiler error? (Choose all that apply.)

A. line 1
B. line 5
C. line 6
D. line 7
E. line 8
F. line 9
G. line 10
H. line 12


DOWNLOAD the answer

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