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

QUESTION 1

Given:

 

1.   interface Animal { void makeNoise(); }

2.   class Horse implements Animal {

3.        Long weight = 1200L;

4.        public void makeNoise() { System.out.println("whinny"); }

05. } 06.

7.   public class Icelandic extends Horse {

8.        public void makeNoise() { System.out.println("vinny"); }

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

10.            Icelandic i1 = new Icelandic();

11.            Icelandic i2 = new Icelandic();

12.            Icelandic i3 = new Icelandic();

13.        i3 = i1; i1 = i2; i2 = null; i3 = i1;

14.    }

15. }

 

When line 14 is reached, how many objects are eligible for the garbage collector?

 

A.    0

B.    1

C.    2

D.    3

E.    4

F.    6

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 2

Given two  files,  GrizzlyBear.java and Salmon.java:

 

01. package animals.mammals; 02.

3.   public class GrizzlyBear extends Bear {

4.         void hunt() {

5.               Salmon s = findSalmon();

6.               s.consume();

07.     }

08. }

 

01. package animals.fish; 02.

3.   public class Salmon extends Fish {

4.         public void consume() { /* do stuff */ }

05. }

 

If both classes are in the correct directories for their packages, and the Mammal class correctly defines the findSalmon() method, which change allows this code to compile?

 

A.    add import animals.mammals.*; at line 2 in  Salmon.java

B.    add import animals.fish.*; at line 2 in  GrizzlyBear.java

C.    add import animals.fish.Salmon.*; at line 2 in  GrizzlyBear.java

D.    add import animals.mammals.GrizzlyBear.*; at  line 2 in Salmon.java

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 3

Given:

 

String[] elements = { "for", "tea", "too" };

String first = (elements.length > 0) ? elements[0] : null;

 

What is the result?

 

A.    Compilation fails.

B.    An exception is thrown at runtime.

C.    The variable first is set to null.

D.    The variable first is set to elements[0].

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 4

A company that makes Computer Assisted Design (CAD) software has, within its application, some utility classes that are used to perform 3D rendering tasks. The company's chief scientist has just improved the performance of one of the utility classes' key rendering algorithms, and has assigned a programmer to replace the old algorithm with the new algorithm. When the programmer begins researching the utility classes, she is happy to discover that the algorithm to be replaced exists in only one class. The programmer reviews that class's API, and replaces the old algorithm with the new algorithm, being careful that her changes adhere strictly to the class's API. Once testing has begun, the programmer discovers that other classes that use the class she changed are no longer working properly. What design flaw is most likely the cause of these new bugs?

 

A.    Inheritance

B.    Tight coupling

C.    Low cohesion

D.    High cohesion

E.    Loose coupling

F.    Object immutability

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 5

Given:

 

class ClassA {

public int numberOfInstances;


 

protected ClassA(int numberOfInstances) {

this.numberOfInstances = numberOfInstances;

}

}

 

public class ExtendedA extends ClassA {

private ExtendedA(int numberOfInstances) {

super(numberOfInstances);

}

 

public static void main(String[] args) { ExtendedA ext = new ExtendedA(420); System.out.print(ext.numberOfInstances);

}

}

 

Which statement is true?

 

A.    420 is the output.

B.    An exception is thrown at runtime.

C.    All constructors must be declared public.

D.    Constructors CANNOT use the private modifier.

E.    Constructors CANNOT use the protected modifier.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 6

Given:

 

class ClassA {}

class ClassB extends ClassA {}

class ClassC extends ClassA {}

 

and:

 

ClassA p0 = new ClassA(); ClassB p1 = new ClassB(); ClassC p2 = new ClassC(); ClassA p3 = new ClassB(); ClassA p4 = new ClassC();

 

Which three are valid? (Choose three.)

 

A.    p0 = p1;

B.    p1 = p2;

C.    p2 = p4;

D.    p2 = (ClassC)p1;

E.    p1 = (ClassB)p3;

F.    p2 = (ClassC)p4;

 

Correct Answer: AEF Section: All Explanation

 

Explanation/Reference:


 

p1 = p2; //type mismatch: cannot convert from ClassC to ClassB p2 = p4; //type mismatch: cannot convert from ClassA to ClassC p2 = (ClassC)p1; //cannot cast from ClassB to ClassC

 

 

QUESTION 7

Given:

 

class Thingy { Meter m = new Meter(); }

 

class Component { void go() { System.out.print("c"); } }

 

class Meter extends Component { void go() { System.out.print("m"); } }

 

class DeluxeThingy extends Thingy {

public static void main(String[] args) { DeluxeThingy dt = new DeluxeThingy(); dt.m.go();

Thingy t = new DeluxeThingy(); t.m.go();

}

}

 

Which two are true? (Choose two.)

 

A.    The output is mm.

B.    The output is mc.

C.    Component is-a Meter.

D.    Component has-a Meter.

E.    DeluxeThingy is-a Component.

F.    DeluxeThingy has-a Component.

 

Correct Answer: AF Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 8

Given:

 

interface Jumper { public void jump(); }

 

class Animal {}

 

class Dog extends Animal { Tail tail;

}

 

class Beagle extends Dog implements Jumper{

public void jump() {}

}

 

class Cat implements Jumper{

public void jump() {}

}

 

Which three are true? (Choose three.)

 

A.    Cat is-a Animal

B.    Cat is-a Jumper

C.    Dog is-a Animal

D.    Dog is-a Jumper

E.    Cat has-a Animal

F.    Beagle has-a Tail

G.   Beagle has-a Jumper

 

Correct Answer: BCF Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 9

Given:

 

import java.util.*;

 

public class WrappedString {

private String s;

 

public WrappedString(String s) { this.s = s; }

 

public static void main(String[] args) { HashSet<Object> hs = new HashSet<Object>(); WrappedString ws1 = new WrappedString("aardvark"); WrappedString ws2 = new WrappedString("aardvark"); String s1 = new String("aardvark");

String s2 = new String("aardvark");

hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2); System.out.println(hs.size()); }

}

 

What is the result?

 

A.    0

B.    1

C.    2

D.    3

E.    4

F.    Compilation fails.

G.   An exception is thrown at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 10

Given:

 

11.  //insert code here

12.     private N min, max;

13.     public N getMin() { return min; }

14.     public N getMax() { return max; }

15.     public void add(N added) {

16.         if (min == null || added.doubleValue() < min.doubleValue())


 

17.             min = added;

18.         if (max == null || added.doubleValue() > max.doubleValue())

19          max = added;

20.   }

21. }

 

Which two, inserted at line 11, will allow the code to compile? (Choose two.)

 

A.    public class MinMax<?> {

B.    public class MinMax<? extends Number> {

C.    public class MinMax<N extends Object> {

D.    public class MinMax<N extends Number> {

E.    public class MinMax<? extends Object> {

F.    public class MinMax<N extends Integer> {

 

Correct Answer: DF Section: All Explanation

 

Explanation/Reference:

 

 

 


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

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

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

[1Z0-851B] Question 41~50  (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-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
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️


📖 Contents 📖