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

QUESTION 11

Given:

 

1.    public class Rainbow {

2.        public enum MyColor {

03.        RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);

4.               private final int rgb;

5.               MyColor(int rgb) { this.rgb = rgb; }

6.        public int getRGB() { return rgb; } 07.       };

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

9.               //insert code here

10.    }

11. }

 

Which code fragment, inserted at line 9, allows the Rainbow class to compile?

 

A.   MyColor skyColor = BLUE;

B.   MyColor treeColor = MyColor.GREEN;

C.   if(RED.getRGB() < BLUE.getRGB()) { }

D.   Compilation fails due to other error(s) in the code.

E.   MyColor purple = new MyColor(0xff00ff);

F.   MyColor purple = MyColor.BLUE + MyColor.RED;

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 12

Given:

 

1.    public class Mud {

2.        //insert code here

3.               System.out.println("hi");

04.    }

05. }

 

And the following five fragments:

 

public static void main(String...a) { public static void main(String.* a) { public static void main(String... a) { public static void main(String[]... a) { public static void main(String...[] a) {

 

How many of the code fragments, inserted independently at line 2, compile?

 

A.   0

B.   1

C.   2

D.   3

E.   4

F.   5

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

public static void main(String...a) { public static void main(String... a) { public static void main(String[]... a) {

 

QUESTION 13

Given:

 

class Atom {

Atom() { System.out.print("atom "); }

}

 

class Rock extends Atom {

Rock(String type) { System.out.print(type); }

}

 

public class Mountain extends Rock { Mountain() {

super("granite ");

new Rock("granite ");

}


 

public static void main(String[] a) { new Mountain(); }

}

 

What is the result?

 

A.   Compilation fails.

B.   atom granite

C.   granite granite

D.   atom granite granite

E.   An exception is thrown at runtime.

F.   atom granite atom granite

 

Correct Answer: F Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 14

Given:

 

01. interface TestA { String toString(); } 02.

3.    public class Test {

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

5.               System.out.println(new TestA() {

6.               public String toString() { return "test"; } 07. });

08.    }

09. }

 

What is the result?

 

A.   test

B.   null

C.   An exception is thrown at runtime.

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

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

F.   Compilation fails because of an error in line 6.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 15

Given:

 

public static void parse(String str) {

try {

float f = Float.parseFloat(str);

} catch (NumberFormatException nfe) { f = 0;

} finally {

System.out.println(f);

}

}


 

public static void main(String[] args) { parse("invalid");

}

What is the result?

 A.  0.0

B.   Compilation fails.

C.   A ParseException is thrown by the parse method at runtime.

D.   A NumberFormatException is thrown by the parse method at runtime.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

f cannot be resolved

 

 

QUESTION 16

Given:

 

1.    public class Blip {

2.        protected int blipvert(int x) { return 0; }

03. }

4.    class Vert extends Blip {

5.        // insert code here

06. }

 

Which five methods, inserted independently at line 5, will compile? (Choose five.)

 

A.   public int blipvert(int x) { return 0; }

B.   private int blipvert(int x) { return 0; }

C.   private int blipvert(long x) { return 0; }

D.   protected long blipvert(int x) { return 0; }

E.   protected int blipvert(long x) { return 0; }

F.   protected long blipvert(long x) { return 0; }

G.   protected long blipvert(int x, int y) { return 0; }

 

Correct Answer: ACEFG Section:  All Explanation

 

Explanation/Reference:

private int blipvert(int x) { return 0; } - Cannot reduce the visibility of the inherited method from Blip

protected long blipvert(int x) { return 0; } - The return type is incompatible with Blip.blipvert(int)

 

 

QUESTION 17

Given:

 

1.    class Super {

2.        private int a;

3.        protected Super(int a) { this.a = a; }

04. }

 

11.  class Sub extends Super {

12.       public Sub(int a) { super(a); }


 

13.       public Sub() { this.a = 5; }

14. }

 

Which two, independently, will allow Sub to compile? (Choose two.)

 

A.   Change line 2 to:

public int a;

B.   Change line 2 to:

protected int a;

C.   Change line 13 to:

public Sub() { this(5); }

D.   Change line 13 to:

public Sub() { super(5); }

E.   Change line 13 to:

public Sub() { super(a); }

 

Correct Answer: CD Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 18

Which Man class properly represents the relationship "Man has a best friend who is a Dog"?

 

A.   class Man extends Dog { }

B.   class Man implements Dog { }

C.   class Man { private BestFriend dog; }

D.   class Man { private Dog bestFriend; }

E.   class Man { private Dog<bestFriend>; }

F.   class Man { private BestFriend<dog>; }

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 19

Given:

 

package test;

 

class Target {

public String name = "hello";

}

 

What can directly access and change the value of the variable name?

 

A.   any class

B.   only the Target class

C.   any class in the test package

D.   any class that extends Target

 

Correct Answer: C Section: All Explanation


 

Explanation/Reference:

 

 

QUESTION 20

Given:

 

11.  abstract class Vehicle { public int speed() { return 0; }

12.  class Car extends Vehicle { public int speed() { return 60; }

13.  class RaceCar extends Car { public int speed() { return 150; } ...

 

21.  RaceCar racer = new RaceCar();

22.  Car car = new RaceCar();

23    Vehicle vehicle = new RaceCar();

24    System.out.println(racer.speed() + ", " + car.speed() + ", " + vehicle.speed());

What is the result?

A.  0, 0, 0

B.  150, 60, 0

C. Compilation fails.

D.  150, 150, 150

E.  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-851B] Question 11~20  (0) 2017.08.11
[1Z0-851B] Question 01~10  (0) 2017.08.11
[1Z0-851A] Question 51~60  (0) 2017.08.05
[1Z0-851A] Question 41~50  (0) 2017.08.05
[1Z0-851A] Question 31~40  (0) 2017.08.05
[1Z0-851A] Question 21~30  (0) 2017.08.05
[1Z0-851A] Question 01~10  (0) 2017.08.04
OCJP Dumps  (0) 2017.07.12
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖