Showing posts with label OCPJP. Show all posts
Showing posts with label OCPJP. Show all posts

Monday, October 24, 2011

Quiz of the Day | OCPJP (35)

Given:

7. public interface Ndesit {
8. /* insert code here */ int score = 8;
9. }

Which 3 are valid on line 8? (Choose 3)
A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected

Sunday, October 9, 2011

Quiz of the day | OCPJP (34)

Given:

3. class K {
4. String name = "kentang ";
5. String makeNoise() { return "ngentang"; }
6. }
7. class S extends K {
8. String name = "surikoyo ";
9. String makeNoise() { return "nyurikoyo"; }
10. }
11. public class ZK {
12. public static void main(String[] args) { new ZK().go(); }
13. void go() {
14. K k = new S();
15. System.out.println(k.name + k.makeNoise());
16. }
17. }

What is the result?

A. kentang nyurikoyo
B. surikoyo nyurikoyo
C. kentang ngentang
D. surikoyo ngentang
E. Compilation fails
F. An exception is thrown at runtime

Saturday, October 8, 2011

Quiz of the day | OCPJP (33)

Given:

1. public class Tingting implements Ayu
{ public void doIt() { } }
2.
3. abstract class Phone1 extends Electronic { }
4.
5. abstract class Phone2 extends Electronic
{ public void doIt(int x) { } }
6.
7. class Phone3 extends Electronic implements Ayu
{ public void doStuff() { } }
8.
9. interface Device { public void doIt(); }

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

A. Compilation succeeds
B. Compilation fails with an error on line 1
C. Compilation fails with an error on line 3
D. Compilation fails with an error on line 5
E. Compilation fails with an error on line 7
F. Compilation fails with an error on line 9

DOWNLOAD the answer

Friday, October 7, 2011

Quiz of the day | OCPJP (32)

Given:

1. class Pocong {
2. public static void main(String[] args) {
3. doStuff(8);
4. doStuff(8,9);
5. }
6. // insert code here
7. }

Which, inserted independently at line 6, will compile? (Choose all that

apply.)

A. static void doStuff(int... doArgs) { }
B. static void doStuff(int[] doArgs) { }
C. static void doStuff(int doArgs...) { }
D. static void doStuff(int... doArgs, int y) { }
E. static void doStuff(int x, int... doArgs) { }


DOWNLOAD the answer

Thursday, October 6, 2011

Quiz of the day | OCPJP (31)

Which method names follow the JavaBeans standard? (Choose all that apply.)

A. addBook
B. getProduct
C. deleteShirt
D. isThree
E. putBall


DOWNLOAD the answer

Wednesday, October 5, 2011

Quiz of the day | OCPJP (30)

Given:

4. class WongJowo {
5. public static void main(String[] args) {
6. for(int __w = 0; __w < 5; __w++) ;
7. int #jw = 8;
8. long [] x [2];
9. Boolean []wj[];
10. enum Lanang { NGGANTENG, GAGAH, PINTER };
11. }
12. }

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

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


DOWNLOAD the answer

Tuesday, October 4, 2011

Quiz of the day | OCPJP (29)

Given:

3. public class Bunga {
4. public enum Kembang { MAWAR, SETAMAN, DESA };
5. public static void main(String[] args) {
6. for(Kembang k : Kembang.values() )
7. ;
8. Kembang [] k2 = Kembang.values();
9. System.out.println(k2[2]);
10. }
11. }

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

A. SETAMAN
B. DESA
C. The output is unpredictable
D. Compilation fails due to an error on line 4
E. Compilation fails due to an error on line 6
F. Compilation fails due to an error on line 8
G. Compilation fails due to an error on line 9


DOWNLOAD the answer

Monday, October 3, 2011

Quiz of the day | OCPJP (28)

Given:

4. public class Kancil extends Kijang {
5. public static void main(String[] args) {
6. Short sikil = 4;
7. System.out.println(jumlah(sikil, 4));
8. }
9. }
10. class Kijang {http://www.blogger.com/img/blank.gif
11. int jumlah(int x, int y) { return x + y; }
12. }

What is the result?

A. 8
B. Compilation fails due to multiple errors
C. Compilation fails due to an error on line 6
D. Compilation fails due to an error on line 7
E. Compilation fails due to an error on line 11

Sunday, October 2, 2011

Quiz of the day | OCPJP (27)

Given two files:

1. package x;
2. public class J {
3. int a = 1;
4. protected int b = 2;
5. public int c = 3;
6. }

3. package y;
4. import x.*;
5. public class H {
6. public static void main(String[] args) {
7. J j = new J();
8. System.out.print(" " + j.a);
9. System.out.print(" " + j.b);
10. System.out.print(" " + j.c);
11. }
12. }

http://www.blogger.com/img/blank.gif
What is the result? (Choose all that apply.)

A. 1 2 3
B. 1 followed by an exception
C. Compilation fails with an error on line 7
D. Compilation fails with an error on line 8
E. Compilation fails with an error on line 9
F. Compilation fails with an error on line 10


DOWNLOAD the answer

Saturday, October 1, 2011

Quiz of the day | OCPJP (26)

Given:

1. enum Kewan {
2. KIRIK("guk"), KUCING("meong"), WEDUS("mbek");
3. String suoro;
4. Kewan(String s) { suoro = s; }
5. }
6. class Enum {
7. static Kewan a;
8. public static void main(String [] args) {
9. System.out.println(a.KIRIK.suoro + " " + a.WEDUS.suoro);
10. }
11. }

What is the result?

A. guk mbek
B. Multiple compilation errors
C. Compilation fails due to an error on line 2
D. Compilation fails due to an error on line 3
E. Compilation fails due to an error on line 4
F. Compilation fails due to an error on line 9


DOWNLOAD the answer

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

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

Wednesday, September 21, 2011

Quiz of the day | OCPJP (16)

Given:

2. import java.text.*;
3. import java.util.*;
4. public class DF {
5. public static void main(String[] args) {
6. DateFormat df1 = DateFormat.getInstance();
7. DateFormat df2 = DateFormat.getInstance(DateFormat.SHORT);
8. DateFormat df3 = DateFormat.getDateInstance(DateFormat.FULL);
9. DateFormat df4 = DateFormat.getDateInstance(DateFormat.EXTENDED);
10. } }

Which are true? (Choose all that apply.)

A. Line 2 is not necessary.
B. Line 3 is not necessary.
C. Compilation fails due to an error on line 6.
D. Compilation fails due to an error on line 7.
E. Compilation fails due to an error on line 8.
F. Compilation fails due to an error on line 9.


DOWNLOAD the answer