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

QUESTION 41

Given:

 

1.    public class Venus {

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

3.                  int[] x = { 1, 2, 3 };

4.                  int y[] = { 4, 5, 6 };

5.                  new Venus().go(x, y);

6.          }

7.

8.                 void go(int[]... z) {

9.                               for (int[] a : z)

10.                                         System.out.print(a[0]);

11.        }

12. }

 

What is the result?

 

A.    1

B.    12

C.    14

        D.  123

E.    Compilation fails.

F.    An exception is thrown at runtime.

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 42

Given:

 

1.    public class Test {

2.                 public enum Dogs {collie, harrier, shepherd};

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

4.                               Dogs myDog = Dogs.shepherd;

5.                               switch (myDog) {

6.                               case collie:

7.                                            System.out.print("collie ");

8.                               case default:

9.                                            System.out.print("retriever ");

10.                            case harrier:

11.                                         System.out.print("harrier ");

12.                }

13.        }

14. }

What is the result?

 

A.    harrier

B.    shepherd

C.    retriever

D.    Compilation fails.

E.    retriever harrier

F.    An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

Test.java:10: illegal start of expression

case default:

^ Test.java:11: : expected

System.out.print("retriever ");

^

2 errors

 

 

QUESTION 43

Given:

 

1.    public class Breaker2 {

2.                 static String o = "";

3.

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

5.                  z: for (int x = 2; x < 7; x++) {


 

6.                          if (x == 3)

7.                                  continue;

8.                          if (x == 5)

9.                                                         break z;

10.                                         o = o + x;

11.                }

12.                            System.out.println(o);

13.        }

14. }

 

What is the result?

 

A.    2

B.    24

C. 234

D. 246

E.  2346

F.   Compilation fails.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 44

Given:

 

public static void main(String[] args) { String str = "null";

if (str == null) { System.out.println("null");

} else (str.length() == 0) { System.out.println("zero");

 

} else {

System.out.println("some");

}

}

 

What is the result?

 

A.    null

B.    zero

C.    some

D.    Compilation fails.

E.    An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

Incorrect else syntax.

 

QUESTION 45

Given:


 

import java.io.IOException;

class A {

public void process() { System.out.print("A,");

}

}

 

13.  class B extends A {

14.      public void process() throws IOException {

15.            super.process();

16.            System.out.print("B,");

17.            throw new IOException();

18.       } 19.

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

21.            try {

22.                  new B().process();

23.            } catch (IOException e) {

24.                  System.out.println("Exception");

25.        }

26.       } 27.}

 

What is the result?

 

A.    Exception

B.    A,B,Exception

C.    Compilation fails because of an error in line 20.

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

E.    A NullPointerException is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

Exception IOException is not compatible with throws clause in A.process()

 

 

QUESTION 46

Given:

 

11.  public void genNumbers() {

12.            ArrayList numbers = new ArrayList(); 13.   for (int i = 0; i < 10; i++) {

14.                  int value = i * ((int) Math.random());

15.                  Integer intObj = new Integer(value);

16.                  numbers.add(intObj);

17.        }

18.        System.out.println(numbers);

19. }

 

Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?

 

A.    Line 16

B.    Line 17

C.    Line 18

D.    Line 19

E.    The object is NOT a candidate for garbage collection.


 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 47

Given:

 

1.    public class GC {

2.                 private Object o;

3.                 private void doSomethingElse(Object obj) { o = obj; }

4.                 public void doSomething() {

5.                               Object o = new Object();

6.                               doSomethingElse(o);

7.                               o = new Object();

8.                               doSomethingElse(null);

9.                               o = null;

10.        }

11. }

 

When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection?

 

A.    Line 5

B.    Line 6

C.    Line 7

D.    Line 8

E.    Line 9

F.    Line 10

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 48

Given:

 

public class Spock {

public static void main(String[] args) { Long tail = 2000L;

Long distance = 1999L; Long story = 1000L;

if ((tail > distance) ^ ((story * 2) == tail)) System.out.print("1");

if ((distance + 1 != tail) ^ ((story * 2) == distance)) System.out.print("2");

}

}

 

What is the result?

 

A.    1

B.    2

C.    12

D.    Compilation fails.

E.    No output is produced.

F.    An exception is thrown at runtime.

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

^ - XOR - returns true if (false ^ true), (true ^ false)

 

 

QUESTION 49

Given:

 

1.    interface DeclareStuff {

2.                 public static final int EASY = 3;

3.

4.          void doStuff(int t);

5.  }

6.

7.    public class TestDeclare implements DeclareStuff {

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

9.                               int x = 5;

10.                            new TestDeclare().doStuff(++x);

11.        }

12.

13.              void doStuff(int s) {

14.                            s += EASY + ++s;

15.                            System.out.println("s " + s);

16.        }

17. }

 

What is the result?

 

A.    s 14

B.    s 16

C.    s 10

D.    Compilation fails.

E.    An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

Cannot reduce the visibility of the inherited method from  DeclareStuff

 

 

QUESTION 50

A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command:

 

java games.cards.Poker

 

What allows the user to do this?

 

A.    put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java

B.    put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jar

C.    put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar

D.    put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java

E.    put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/*.jar

F.    put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/ Poker.jar

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

 

 


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

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

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

[1Z0-851][OCAJP] Dump 문제 1~10  (0) 2021.12.30
[1Z0-851E] Question 21~30  (0) 2017.08.15
[1Z0-851E] Question 11~20  (0) 2017.08.15
[1Z0-851E] Question 01~10  (0) 2017.08.15
[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-851D] Question 01~10  (0) 2017.08.13
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️


📖 Contents 📖