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

QUESTION 41

Given:

 

class Snoochy { Boochy booch;

 

public Snoochy() { booch = new Boochy(this); }

}

 

class Boochy { Snoochy snooch;

 

public Boochy(Snoochy s) { snooch = s; }

}

 

And the statements:

 

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

22.      Snoochy snoog = new Snoochy();

23.      snoog = null;

24.      // more code here

25. }

 

Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line 23 executes?

 

A.    None of these objects are eligible for garbage collection.

B.    Only the object referenced by booch is eligible for garbage collection.

C.    Only the object referenced by snoog is eligible for garbage collection.

D.    Only the object referenced by snooch is eligible for garbage collection.

E.    The objects referenced by snooch and booch are eligible for garbage collection.

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 42

Given:

 

4.   class Payload {

5.        private int weight;

6.        public Payload (int w) { weight = w; }

7.        public void setWeight(int w) { weight = w; }

8.        public String toString() { return Integer.toString(weight); }

09. } 10.

11.  public class TestPayload {


 

12.      static void changePayload(Payload p) { /* insert code */ }

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

14.            Payload p = new Payload(200);

15.            p.setWeight(1024);

16.            changePayload(p);

17.            System.out.println("p is " + p);

18.    }

19. }

 

Which code fragment, inserted at the end of line 12, produces the output p is 420?

 

A.    p.setWeight(420);

B.    p.changePayload(420);

C.    p = new Payload(420);

D.    Payload.setWeight(420);

E.    p = Payload.setWeight(420);

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 43

Given:

 

public static void test(String str) {

int check = 4;

if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", ");

} else {

System.out.print(str.charAt(0) + ", ");

}

}

 

and the invocation:

 

test("four");

test("tee");

test("to");

 

What is the result?

 

A.    r, t, t,

B.    r, e, o,

C.    Compilation fails.

D.    An exception is thrown at runtime.

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 44

Given classes defined in two different files:

 

package util;

public class BitUtils {


 

private static void process(byte[] b) {}

}

 

1.   package app;

2.   public class SomeApp {

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

4.             byte[] bytes = new byte[256];

5.             // insert code here

06.    }

07. }

 

What is required at line 5 in class SomeApp to use the process method of BitUtils?

 

A.    process(bytes);

B.    BitUtils.process(bytes);

C.    app.BitUtils.process(bytes);

D.    util.BitUtils.process(bytes);

E.    import util.BitUtils.*; process(bytes);

F.    SomeApp cannot use the process method in BitUtils.

 

Correct Answer: F Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 45

Given:

 

public class Pass2 {

public void main(String [] args) {

int x = 6;

Pass2 p = new Pass2(); p.doStuff(x);

System.out.print(" main x = " + x);

}

 

void doStuff(int x) {

System.out.print(" doStuff x = " + x++);

}

}

 

And the command-line invocations:

 

javac Pass2.java java Pass2 5

 

What is the result?

 

A.    Compilation fails.

B.    An exception is thrown at runtime.

C.    doStuff x = 6 main x = 6

D.    doStuff x = 6 main x = 7

E.    doStuff x = 7 main x = 6

F.    doStuff x = 7 main x = 7

 

Correct Answer: B

Section: All


 

Explanation

 

Explanation/Reference:

Missing static in main method signature.

 

 

QUESTION 46

Given:

 

public class Test {

public enum Dogs {collie, harrier};

 

public static void main(String [] args) { Dogs myDog = Dogs.collie;

switch (myDog) {

case collie:

System.out.print("collie ");

case harrier:

System.out.print("harrier ");

}

}

}

 

What is the result?

 

A.    collie

B.    harrier

C.    Compilation fails.

D.    collie harrier

E.    An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 47

Given:

 

public class Donkey {

public static void main(String[] args) {

boolean assertsOn = false;

assert (assertsOn) : assertsOn = true; if(assertsOn) {

System.out.println("assert is on");

}

}

}

 

If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results?

 

A.    no output

B.    no output assert is on

C.    assert is on

D.    no output

An AssertionError is thrown.

E.    assert is on

An AssertionError is thrown.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 48

Given:

 

static void test() {

try {

String x = null; System.out.print(x.toString() + " ");

}

finally { System.out.print("finally "); }

}

 

public static void main(String[] args) {

try { test(); }

catch (Exception ex) { System.out.print("exception "); }

}

 

What is the result?

 

A.    null

B.    finally

C.    null finally

D.    Compilation fails.

E.    finally exception

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 49

Given:

 

static void test() throws Error {

if (true) throw new AssertionError(); System.out.print("test ");

}

 

public static void main(String[] args) {

try { test(); }

catch (Exception ex) { System.out.print("exception "); } System.out.print("end ");

}

 

What is the result?

 

A.    end

B.    Compilation fails.

C.    exception end

D.    exception test end

E.    A Throwable is thrown by main.

F.    An Exception is thrown by main.

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 50

Given:

 

1.   class TestException extends Exception { }

2.   class A {

3.        public String sayHello(String name) throws TestException {

4.             if(name == null) throw new TestException();

05       return "Hello " + name;

06.    }

07. }

8.   public class TestA {

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

10.            new A().sayHello("Aiko");

11.    }

12. }

 

Which statement is true?

 

A.    Compilation succeeds.

B.    Class A does not compile.

C.    The method declared on line 9 cannot be modified to throw TestException.

D.    TestA compiles if line 10 is enclosed in a try/catch block that catches TestException.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

 


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

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

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

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


📖 Contents 📖