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

QUESTION 31

Click the Exhibit button.

 

1.    import java.util.*;

2.    public class TestSet{

3.                 enum Example {ONE, TWO, THREE }

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

5.                               Collection coll = new ArrayList();

6.                               coll.add(Example.THREE);

7.                               coll.add(Example.THREE);

8.                               coll.add(Example.THREE);

9.                               coll.add(Example.TWO);

10.                            coll.add(Example.TWO);

11.                            coll.add(Example.ONE);

12.                            Set set = new HashSet(coll);

13.        }

14. }

 

Which statement is true about the set variable on line 12?

 

A.    The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved.

B.    The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.

C.    The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be preserved.

D.    The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be preserved.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 32

Given:

 

public class Person {

private String name, comment;

private int age;

 

public Person(String n, int a, String c) { name = n;

age = a; comment = c;

}

 

public boolean equals(Object o) {

if (!(o instanceof Person))

return false; Person p = (Person) o;

return age == p.age && name.equals(p.name);

}

}

 

What is the appropriate definition of the hashCode method in class Person?

 

A.    return super.hashCode();

B.    return name.hashCode() + age * 7;

C.    return name.hashCode() + comment.hashCode() / 2;

D.    return name.hashCode() + comment.hashCode() / 2 - age * 3;

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 33

Given:

 

public class Key { private long id1; private long id2;

 

// class Key methods

}

 

A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key? (Choose two.)

 

A.    public int hashCode()

B.    public boolean equals(Key k)

C.    public int compareTo(Object o)

D.    public boolean equals(Object o)

E.    public boolean compareTo(Key k)

 

Correct Answer: AD Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 34

Given:

 

3.   import java.util.*;

4.   public class Hancock {

5.             // insert code here

6.             list.add("foo");

07.    }

08. }

 

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

 

A.    public void addStrings(List list) {

B.    public void addStrings(List<String> list) {

C.    public void addStrings(List<? super String> list) {

D.    public void addStrings(List<? extends String> list) {

 

Correct Answer: BC Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 35

A programmer has an algorithm that requires a java.util.List that provides an efficient implementation of add(0, object), but does NOT need to support quick random access. What supports these requirements?

 

A.    java.util.Queue

B.    java.util.ArrayList

C.    java.util.LinearList

D.    java.util.LinkedList

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 36

Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true? (Choose two.)

 

A.    The class implements java.lang.Comparable.

B.    The class implements java.util.Comparator.

C.    The interface used to implement sorting allows this class to define only one sort sequence.

D.    The interface used to implement sorting allows this class to define many different sort sequences.


 

Correct Answer: AC Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 37

Given:

 

1.    import java.util.*;

2.

3.    public class Explorer3 {

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

5.                               TreeSet<Integer> s = new TreeSet<Integer>();

6.                               TreeSet<Integer> subs = new TreeSet<Integer>();

7.                  for (int i = 606; i < 613; i++)

8.                          if (i % 2 == 0)

9.                                  s.add(i);

10.

 

subs = (TreeSet) s.subSet(608, true, 611, true);

11.

 

subs.add(629);

12.

 

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

13.

}

 

14. }

 

 

What is the result?

 

A.    Compilation fails.

B.    An exception is thrown at runtime. C.  [608, 610, 612, 629] [608, 610]

D.  [608, 610, 612, 629] [608, 610, 629]

E.  [606, 608, 610, 612, 629] [608, 610]

F.   [606, 608, 610, 612, 629] [608, 610, 629]

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

Exception in thread "main" java.lang.IllegalArgumentException: key out of range

at java.util.TreeMap$NavigableSubMap.put(TreeMap.java:1386) at java.util.TreeSet.add(TreeSet.java:238)

at Explorer3.main(Explorer3.java:11)

 

 

QUESTION 38

Given:

 

1.    import java.util.*;

2.

3.    public class LetterASort {

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

5.                               ArrayList<String> strings = new ArrayList<String>();

6.                               strings.add("aAaA");

7.                               strings.add("AaA");

8.                               strings.add("aAa");

9.                               strings.add("AAaa");

10.                            Collections.sort(strings);


 

11.                            for (String s : strings) {

12.                                         System.out.print(s + " ");

13.                }

14.        }

15. }

 

What is the result?

 

A.    Compilation fails.

B.    aAaA aAa AAaa AaA

C.    AAaa AaA aAa aAaA

D.    AaA AAaa aAaA aAa

E.    aAa AaA aAaA AAaa

F.    An exception is thrown at runtime.

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 39

Given:

 

1.    public class Mule {

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

3.                               boolean assert = true;

4.                               if(assert) {

5.                                            System.out.println("assert is true");

6.                  }

7.          }

8.  }

 

Which command-line invocations will  compile?

 

A.    javac Mule.java

B.    javac -source 1.3 Mule.java

C.    javac -source 1.4 Mule.java

D.    javac -source 1.5 Mule.java

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 40

Click the Exhibit button

 

1.    public class A {

2.                 public void method1(){

3.                               B b = new B();

4.                               b.method2();

5.                               // more code here

6.          }

7.  }


 

1.    public class B{

2.                 public void method2() {

3.                               C c = new C();

4.                               c.method3();

5.                               // more code here

6.          }

7.  }

 

1.    public class C {

2.                 public void method3(){

3.                               // more code here

4.          }

5.  }

 

Given:

 

25.  try {

26.        A a = new A();

27.        a.method1();

28.  } catch (Exception e) {

29.        System.out.print("an error occurred");

30. }

 

Which two statements are true if a NullPointerException is thrown on line 3 of class C? (Choose two.)

 

A.    The application will crash.

B.    The code on line 29 will be executed.

C.    The code on line 5 of class A will execute.

D.    The code on line 5 of class B will execute.

E.    The exception will be propagated back to line 27.

 

Correct Answer: BE Section: All Explanation

 

Explanation/Reference:

 

 

 

 


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

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

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

[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 41~50  (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
[1Z0-851C] Question 51~60  (0) 2017.08.12
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖