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

QUESTION 41

Given:

 

33.  try {

34.       //some code here

35.  } catch (NullPointerException e1) {

36.       System.out.print("a");

37.  } catch (Exception e2) {

38.       System.out.print("b");

39.  } finally {

40.       System.out.print("c");

41. }

 

If some sort of exception is thrown at line 34, which output is possible?

 

A.   a

B.   b

C.   c

D.   ac

E.   abc

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 42

Given:

 

31.  //some code here line 31

32.  try {

33.        //some code here line 33

34.  } catch (NullPointerException e1) {

35.        //some code here line 35

36.  } finally {

37.        //some code here line 37

38. }

 

Under which three circumstances will the code on line 37 be executed? (Choose three.)

 

A.   The instance gets garbage collected.

B.   The code on line 33 throws an exception.

C.   The code on line 35 throws an exception.

D.   The code on line 31 throws an exception.

E.   The code on line 33 executes successfully.

 

Correct Answer: BCE Section: All Explanation


 

Explanation/Reference:

 

 

QUESTION 43

Given:

 

int x = 0; int y = 10; do {

y--;

++x;

} while (x < 5); System.out.print(x + "," + y);

What is the result?

A.  5,6

B.  5,5

C.  6,5

D.  6,6

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 44

Given:

 

public class Donkey2 {

public static void main(String[] args) {

boolean assertsOn = true;

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: C Section: All Explanation

 

Explanation/Reference:


 

QUESTION 45

Given:

 

1.    public class A{

2.       public void method1() {

3.               try {

4.                     B b = new B();

5.                     b.method2();

6.                     //more code here

7.               } catch (TestException te){

8.                     throw new RuntimeException(te);

09.        }

10.    }

11. }

 

1.    public class B{

2.        public void method2() throws TestException {

3.       //more code here 04 }

05. }

 

01. class TestException extends Exception {

02. }

 

31.  public void method() {

32.       A a = new A();

33.       a.method1();

34. }

 

Which statement is true if a TestException is thrown on line 3 of class B?

 

A.   Line 33 must be called within a try block.

B.   The exception thrown by method1 in class A is not required to be caught.

C.   The method declared on line 31 must be declared to throw a RuntimeException.

D.   On line 5 of class A, the call to method2 of class B does not need to be placed in a try/catch block.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 46

Given:

 

Float pi = new Float(3.14f);

if (pi > 3) {

System.out.print("pi is bigger than 3. ");

}

else {

System.out.print("pi is not bigger than 3. ");

}

finally {

System.out.println("Have a nice day.");

}

 

What is the result?

 

A.   Compilation fails.

B.   pi is bigger than 3.

C.   An exception occurs at runtime.

D.   pi is bigger than 3. Have a nice day.

E.   pi is not bigger than 3. Have a nice day.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

Syntax error on token finally

 

 

QUESTION 47

Given:

 

1.    public class Boxer1{

2.        Integer i;

3.        int x;

4.        public Boxer1(int y) {

5.               x = i+y;

6.               System.out.println(x);

07.    }

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

9.               new Boxer1(new Integer(4));

10.    }

11. }

 

What is the result?

 

A.   The value "4" is printed at the command line.

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

C.   Compilation fails because of an error in line 9.

D.   A NullPointerException occurs at runtime.

E.   A NumberFormatException occurs at runtime.

F.   An IllegalStateException occurs at runtime.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 48

Given:

 

1.    public class Person {

2.        private String name;

3.        public Person(String name) { this.name = name; }

4.        public boolean equals(Person p) {

5.               return p.name.equals(this.name);

06.    }

07. }

 

Which statement is true?

 

A.   The equals method does NOT properly override the Object.equals method.

B.   Compilation fails because the private attribute p.name cannot be accessed in line 5.

C.   To work correctly with hash-based data structures, this class must also implement the hashCode method.

D.   When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 49

Which two statements are true about the hashCode method? (Choose two.)

 

A.   The hashCode method for a given class can be used to test for object equality and object inequality for that class.

B.   The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.

C.   The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.

D.   The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.

E.   The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.

 

Correct Answer: CE Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 50

Given a pre-generics implementation of a method:

 

11.  public static int sum(List list) {

12.       int sum = 0;

13.       for ( Iterator iter = list.iterator(); iter.hasNext(); ) {

14.             int i = ((Integer)iter.next()).intValue();

15.             sum += i;

16.    }

17.    return sum;

18. }

 

What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)

 

A.   Remove line 14.

B.   Replace line 14 with int i = iter.next();

C.   Replace line 13 with for (int i : intList) {

D.   Replace line 13 with for (Iterator iter : intList) {

E.   Replace the method declaration with sum(List<int> intList)

F.   Replace the method declaration with sum(List<Integer> intList)

 

Correct Answer: ACF Section: All Explanation

 

Explanation/Reference:

 

 


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

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

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

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


📖 Contents 📖