별의 공부 블로그 🧑🏻‍💻
728x90
728x170

QUESTION 1

Given:

 

33.  Date d = new Date(0);

34.  String ds = "December 15, 2004";

35.  // insert code here

36.  try {

37.        d = df.parse(ds);

38. }

39.  catch(ParseException e) {

40.        System.out.println("Unable to parse " + ds);

41. }

42. // insert code here too

 

What creates the appropriate DateFormat object and adds a day to the Date object?

 

A.    35. DateFormat df = DateFormat.getDateFormat(); 42. d.setTime( (60 * 60 * 24) + d.getTime());

B.    35. DateFormat df = DateFormat.getDateInstance(); 42. d.setTime( (1000 * 60 * 60 * 24) + d.getTime());

C.    35. DateFormat df = DateFormat.getDateFormat();

42. d.setLocalTime( (1000*60*60*24) + d.getLocalTime());

D.    35. DateFormat df = DateFormat.getDateInstance();

42. d.setLocalTime( (60 * 60 * 24) + d.getLocalTime());

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 2

Given:

 

1.    public class KungFu {

2.                 public static void main(String[] args) {

3.                               Integer x = 400;

4.                               Integer y = x;

5.                  x++;

6.

 

StringBuilder sb1 = new StringBuilder("123");

7.

 

StringBuilder sb2 = sb1;

8.

 

sb1.append("5");

9.

 

System.out.println((x == y) + " " + (sb1 == sb2));

10.

}

 

11. }

 

 

What is the result?

 

A.    true true

B.    false true

C.    true false

D.    false false

E.    Compilation fails.

F.    An exception is thrown at runtime.

 

Correct Answer: B

Section: All


 

Explanation Explanation/Reference:

 

 

QUESTION 3

Given:

 

11.  class Converter {

12.      public static void main(String[] args) {

13.            Integer i = args[0];

14.            int j = 12;

15.            System.out.println("It is " + (j == i) + " that j==i.");

16.    }

17. }

 

What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?

 

A.    It is true that j==i.

B.    It is false that j==i.

C.    An exception is thrown at runtime.

D.    Compilation fails because of an error in line 13.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

Integer i = args[0]; Type mismatch: cannot convert from String to Integer

 

 

QUESTION 4

Given

 

1.    public class A {

2.                 public String doit(int x, int y){

3.                               return "a";

4.          }

5.

6.                 public String doit(int... vals){

7.                               return "b";

8.          }

9.  }

 

and:

 

25.   A a = new A();

26.   System.out.println(a.doit(4, 5));

 

What is the result?

 

A.    Line 26 prints "a" to System.out.

B.    Line 26 prints "b" to System.out.

C.    An exception is thrown at line 26 at runtime.

D.    Compilation of class A will fail due to an error in line 6.

 

Correct Answer: A Section: All Explanation


 

Explanation/Reference:

 

 

QUESTION 5

Which two code fragments correctly create and initialize a static array of int  elements? (Choose two.)

 

A.    static final int[] a = { 100,200 };

B.    static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }

C.    static final int[] a = new int[2]{ 100,200 };

D.    static final int[] a;

static void init() { a = new int[3]; a[0]=100; a[1]=200; }

 

Correct Answer: AB Section: All Explanation

 

Explanation/Reference:

static final int[] a = new int[2]{ 100,200 }; - Cannot define dimension expression when an array initializer is provided.

static final int[] a; - the blank final field may not have been initialized

static void init() { a = new int[3]; a[0]=100; a[1]=200; } - the final field a cannot be assigned

 

 

QUESTION 6

Given:

 

1.    public class Plant {

2.                 private String name;

3.

4.                 public Plant(String name) {

5.                               this.name = name;

6.          }

7.

8.                 public String getName() {

9.                               return name;

10.        }

11. }

1.    public class Tree extends Plant {

2.                 public void growFruit() {

3.          }

4.

5.          public void dropLeaves() {

6.          }

7.  }

 

Which statement is true?

 

A.    The code will compile without changes.

B.    The code will compile if public Tree() { Plant(); } is added to the Tree class.

C.    The code will compile if public Plant() { Tree(); } is added to the Plant class.

D.    The code will compile if public Plant() { this("fern"); } is added to the Plant class.

E.    The code will compile if public Plant() { Plant("fern"); } is added to the Plant  class.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:


 

QUESTION 7

Click the Exhibit button.

 

1.       public class GoTest {

2.                 public static void main(String[] args) {

3.                               Sente a = new Sente(); a.go();

4.                               Goban b = new Goban(); b.go();

5.                               Stone c = new Stone(); c.go();

6.          }

7.    }

8.

9.       class Sente implements Go {

10.              public void go(){

11.                            System.out.println("go in Sente");

12.        }

13.  }

14.

15.    class Goban extends Sente {

16.              public void go(){

17.                            System.out.println("go in Goban");

18.        }

19.

20.  }

21.   class Stone extends Goban implements Go{

22.  }

23.

24.   interface Go { public void go(); }

 

What is the result?

 

A.    go in Goban go in Sente go in Sente

B.    go in Sente go in Sente go in Goban

C.    go in Sente go in Goban go in Goban

D.    go in Goban go in Goban go in Sente

E.    Compilation fails because of an error in line 17.

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 8

Given:

 

public interface A111 { String s = "yo";

 

public void method1();

}

 

interface B {

}

 

interface C extends A111, B {

public void method1();


 

public void method1(int x);

}

 

What is the result?

 

A.    Compilation succeeds.

B.    Compilation fails due to multiple errors.

C.    Compilation fails due to an error only on line 20.

D.    Compilation fails due to an error only on line 21.

E.    Compilation fails due to an error only on line 22.

F.    Compilation fails due to an error only on line 12.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 9

Click the Exhibit button.

 

10.  interface Foo{

11.      int bar();

12. } 13.

14. public class Beta { 15.

16.      class A implements Foo {

17.            public int bar(){ return 1; }

18.       } 19.

20.    public int fubar(Foo foo){ return foo.bar(); } 21.

22.    public void testFoo(){ 23.

24.            class A implements Foo{

25.                  public int bar(){return 2;}

26.        }

27.

28.        System.out.println(fubar(new A()));

29.       } 30.

31.      public static void main(String[] args) {

32.            new Beta().testFoo();

33.    }

34. }

 

Which three statements are true? (Choose three.)

 

A.    Compilation fails.

B.    The code compiles and the output is 2.

C.    If lines 16, 17 and 18 were removed, compilation would  fail.

D.    If lines 24, 25 and 26 were removed, compilation would  fail.

E.    If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.

F.    If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

 

Correct Answer: BEF Section: All Explanation


 

Explanation/Reference:

 

 

QUESTION 10

Given:

 

class Alpha {

public void foo() { System.out.print("Afoo "); }

}

public class Beta extends Alpha {

public void foo() { System.out.print("Bfoo "); }

public static void main(String[] args) { Alpha a = new Beta();

Beta b = (Beta)a; a.foo();

b.foo();

}

}

 

What is the result?

 

A.    Afoo Afoo

B.    Afoo Bfoo

C.    Bfoo Afoo

D.    Bfoo Bfoo

E.    Compilation fails.

F.    An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

 

 


Source from : Oracle.Exactexams.1z0-851.v2013-11-27.by.SomeBody ().pdf

728x90
그리드형(광고전용)

'Certificate > OCAJP' 카테고리의 다른 글

[1Z0-851D] Question 41~50  (0) 2017.08.13
[1Z0-851D] Question 31~40  (0) 2017.08.13
[1Z0-851D] Question 21~30  (0) 2017.08.13
[1Z0-851D] Question 11~20  (0) 2017.08.13
[1Z0-851C] Question 51~60  (0) 2017.08.12
[1Z0-851C] Question 41~50  (0) 2017.08.12
[1Z0-851C] Question 31~40  (0) 2017.08.12
[1Z0-851C] Question 21~30  (0) 2017.08.12
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖