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

QUESTION 21

A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself. What design issue has the team discovered?

 

A.    Tight coupling

B.    Low cohesion

C.    High cohesion

D.    Loose coupling

E.    Weak encapsulation

F.    Strong encapsulation

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

QUESTION 22

Given a method that must ensure that its parameter is not null:

 

11.  public void someMethod(Object value) {

12.  // check for null value

...

20. System.out.println(value.getClass());

21. }

 

What, inserted at line 12, is the appropriate way to handle a null value?

 

A.    assert value == null;

B.    assert value != null, "value is null";

C.    if (value == null) { throw new AssertionException("value is null"); }

D.    if (value == null) { throw new IllegalArgumentException("value is null"); }

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 23

Given:

 

1.    public class Target {

2.                 private int i = 0;

3.                 public int addOne() {

4.                               return ++i;

5.          }

6.  }

And:

 

1.    public class Client {

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

3.                               System.out.println(new Target().addOne());

4.          }

5.  }

Which change can you make to Target without affecting Client?

 

A.    Line 4 of class Target can be changed to return i++;

B.    Line 2 of class Target can be changed to private int i = 1;

C.    Line 3 of class Target can be changed to private int addOne(){

D.    Line 2 of class Target can be changed to private Integer i = 0;

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 24

Given:

 

class Animal {

public String noise() {

return "peep";

}

}

 

class Dog extends Animal {

public String noise() {

return "bark";

}

}

 

class Cat extends Animal {

public String noise() {

return "meow";

}

}

 

30.  Animal animal = new Dog();

31.  Cat cat = (Cat)animal;

32.  System.out.println(cat.noise());

 

What is the result?

 

A.    peep

B.    bark

C.    meow

D.    Compilation fails.

E.    An exception is thrown at runtime.

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

Exception in thread "main" java.lang.ClassCastException: Dog cannot be cast to Cat

at Client.main(Client.java:12)

 

 

QUESTION 25

Given:

 

abstract class A {

abstract void a1();

 

void a2() {

}

}

 

class B extends A {

void a1() {

}

 

void a2() {

}

}

 

class C extends B {

void c1() {

}

}

 

And:

 

A x = new B();


 

C y = new C(); A z = new C();

What are four valid examples of polymorphic method calls? (Choose four.)

A.  x.a2();

B.  z.a2();

C.  z.c1();

D.  z.a1();

E.  y.c1();

F.  x.a1();

 

Correct Answer: ABDF Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 26

Given:

 

class Employee { String name; double baseSalary;

 

Employee(String name, double baseSalary) {

this.name = name;

this.baseSalary = baseSalary;

}

}

 

9.   public class SalesPerson extends Employee {

10.      double commission; 11.

12.      public SalesPerson(String name, double baseSalary, double commission) {

13.            // insert code here

14.    }

15. }

 

Which two code fragments, inserted independently at line 13, will compile? (Choose two.)

 

A.    super(name, baseSalary);

B.    this.commission = commission;

C.    super(); this.commission = commission;

D.    this.commission = commission; super();

E.    super(name, baseSalary); this.commission = commission;

F.    this.commission = commission; super(name, baseSalary);

G.   super(name, baseSalary, commission);

 

Correct Answer: AE Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 27

Given that: Gadget has-a Sprocket and Gadget has-a Spring and Gadget is-a Widget and Widget has-a


 

Sprocket Which two code fragments represent these relationships? (Choose two.)

 

A.    class Widget {

Sprocket s;

}

 

class Gadget extends Widget { Spring s;

}

B.    class Widget {

}

 

class Gadget extends Widget { Spring s1;

Sprocket s2;

}

C.    class Widget {

Sprocket s1; Spring s2;

}

 

class Gadget extends Widget {

}

D.    class Gadget {

Spring s;

}

 

class Widget extends Gadget { Sprocket s;

}

E.    class Gadget {

}

 

class Widget extends Gadget { Sprocket s1;

Spring s2;

}

F.    class Gadget {

Spring s1; Sprocket s2;

}

 

class Widget extends Gadget {

}

 

Correct Answer: AC Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 28

Given:

 

class Pizza {

java.util.ArrayList toppings;

 

public final void addTopping(String topping) { toppings.add(topping);

}

public void removeTopping(String topping) {


 

toppings.remove(topping);

}

}

 

public class PepperoniPizza extends Pizza {

public void addTopping(String topping) { System.out.println("Cannot add Toppings");

}

 

public static void main(String[] args) { Pizza pizza = new PepperoniPizza(); pizza.addTopping("Mushrooms"); pizza.removeTopping("Peperoni");

}

}

 

What is the result?

 

A.    Compilation fails.

B.    Cannot add Toppings

C.    The code runs with no output.

D.    A NullPointerException is thrown in Line 4.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 29

Which three statements are true? (Choose three.)

 

A.    A final method in class X can be abstract if and only if X is abstract.

B.    A protected method in class X can be overridden by any subclass of X.

C.    A private static method can be called only within other static methods in class X.

D.    A non-static public final method in class X can be overridden in any subclass of X.

E.    A public static method in class X can be called by a subclass of X without explicitly referencing the class X.

F.    A method with the same signature as a private final method in class X can be implemented in a subclass of X.

G.   A protected method in class X can be overridden by a subclass of X only if the subclass is in the same package as X.

 

Correct Answer: BEF Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 30

Click the Exhibit button.

 

1.    public class Car {

2.                 private int wheelCount;

3.                 private String vin;

4.                 public Car(String vin){

5.                               this.vin = vin;

6.                               this.wheelCount = 4;


 

7.          }

8.                 public String drive(){

9.                               return "zoom-zoom";

10.        }

11.              public String getInfo() {

12.                            return "VIN: " + vin + " wheels: " + wheelCount;

13.        }

14. } And

1.    public class MeGo extends Car {

2.                 public MeGo(String vin) {

3.                               this.wheelCount = 3;

4.          }

5.  }

 

What two must the programmer do to correct the compilation errors? (Choose two.)

 

A.    insert a call to this() in the Car constructor

B.    insert a call to this() in the MeGo constructor

C.    insert a call to super() in the MeGo constructor

D.    insert a call to super(vin) in the MeGo constructor

E.    change the wheelCount variable in Car to protected

F.    change line 3 in the MeGo class to super.wheelCount = 3;

 

Correct Answer: DE Section: All Explanation

 

Explanation/Reference:

 

 

 

 


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

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

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

[1Z0-851E] Question 11~20  (0) 2017.08.15
[1Z0-851E] Question 01~10  (0) 2017.08.15
[1Z0-851D] Question 41~50  (0) 2017.08.13
[1Z0-851D] Question 31~40  (0) 2017.08.13
[1Z0-851D] Question 11~20  (0) 2017.08.13
[1Z0-851D] Question 01~10  (0) 2017.08.13
[1Z0-851C] Question 51~60  (0) 2017.08.12
[1Z0-851C] Question 41~50  (0) 2017.08.12
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️


📖 Contents 📖