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

QUESTION 51

Given:

 

public static Collection get() { Collection sorted = new LinkedList();

sorted.add("B"); sorted.add("C"); sorted.add("A");

return sorted;

}

 

public static void main(String[] args) {

for (Object obj: get()) { System.out.print(obj + ", ");

}

}

 

What is the result?

 

A.    A, B, C,

B.    B, C, A,

C.    Compilation fails.

D.    The code runs with no output.

E.    An exception is thrown at runtime.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 52

Given:

 

8.   static class A {

9.        void process() throws Exception { throw new Exception(); }

13. }

14.  static class B extends A {

15.      void process() { System.out.println("B"); }

16. }

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

18.      new B().process();

19. }

 

What is the result?

 

A.    B

B.    The code runs with no output.

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

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

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

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 53

Given:

 

public class Foo { static int[] a; static { a[0]=2; }

public static void main( String[] args ) {}

}

 

Which exception or error will be thrown when a programmer attempts to run this code?

 

A.    java.lang.StackOverflowError

B.    java.lang.IllegalStateException

C.    java.lang.ExceptionInInitializerError

D.    java.lang.ArrayIndexOutOfBoundsException

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:


 

QUESTION 54

Given:

 

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

12.      Integer i = new Integer(1) + new Integer(2);

13.      switch(i) {

14.            case 3: System.out.println("three"); break;

15.            default: System.out.println("other"); break;

16.    }

17. }

 

What is the result?

 

A.    three

B.    other

C.    An exception is thrown at runtime.

D.    Compilation fails because of an error on line 12.

E.    Compilation fails because of an error on line 13.

F.    Compilation fails because of an error on line 15.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 55

Given:

 

public static Iterator reverse(List list) { Collections.reverse(list);

return list.iterator();

}

 

public static void main(String[] args) { List list = new ArrayList();

list.add("1"); list.add("2"); list.add("3");

for (Object obj: reverse(list)) System.out.print(obj + ", ");

}

What is the result?

      A.  3, 2, 1,

      B.  1, 2, 3,

C.    Compilation fails.

D.    The code runs with no output.

E.    An exception is thrown at runtime.

 

Correct Answer: C Section: All Explanation

 

Explanation/Reference:

Can only iterate over an array or an instance of java.lang.Iterable

 

 

QUESTION 56

Given:


 

1.   public class TestString3 {

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

3.             // insert code here

4.             System.out.println(s);

05.    }

06. }

Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.)

      A.  String s = "123456789"; s = (s-"123").replace(1,3,"24") - "89";

B.    StringBuffer s = new StringBuffer("123456789"); s.delete(0,3).replace(1,3,"24").delete(4,6);

C.    StringBuffer s = new StringBuffer("123456789"); s.substring(3,6).delete(1,3).insert(1, "24");

D.    StringBuilder s = new StringBuilder("123456789"); s.substring(3,6).delete(1,2).insert(1, "24");

E.    StringBuilder s = new StringBuilder("123456789"); delete(0,3).delete(1,3).delete(2,5).insert(1, "24");

 

Correct Answer: BE Section: All Explanation

 

Explanation/Reference:

The operator - is undefined for argument type(s) String, String The metod delete(int, int) is undefined for type String

 

 

QUESTION 57

Given:

 

1.  d is a valid, non-null Date object

2.  df is a valid, non-null DateFormat object set to the current  locale

 

What outputs the current locale's country name and the appropriate version of d's date?

 

A.    Locale loc = Locale.getLocale(); System.out.println(loc.getDisplayCountry()

+ " " + df.format(d));

B.    Locale loc = Locale.getDefault(); System.out.println(loc.getDisplayCountry()

+ " " + df.format(d));

C.    Locale loc = Locale.getLocale(); System.out.println(loc.getDisplayCountry()

+ " " + df.setDateFormat(d));

D.    Locale loc = Locale.getDefault(); System.out.println(loc.getDisplayCountry()

+ " " + df.setDateFormat(d));

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

There is no getLocale method in class Locale.

 

public static Locale getDefault()

Gets the current value of the default locale for this instance of  the Java Virtual Machine.

 

The Java Virtual Machine sets the default locale during startup based on the host environment. It is used


 

by many locale-sensitive methods if no locale is explicitly specified. It can be changed using the setDefault method.

 

Returns:

the default locale for this instance of the Java Virtual Machine

 

 

QUESTION 58

What is the output if the main() method is run?

 

public class Starter extends Thread {

private int x = 2;

 

public static void main(String[] args) throws Exception {

new Starter().makeItSo();

}

 

public Starter(){ x = 5;

start();

}

 

public void makeItSo() throws Exception { join();

x = x - 1; System.out.println(x);

}

 

public void run() { x *= 2; }

}

 

A.    4

B.    5

C.    8

D.    9

E.    Compilation fails.

F.    An exception is thrown at runtime.

G.   It is impossible to determine for certain.

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 59

Given a correctly compiled class whose source code is:

 

1.    package com.sun.sjcp;

2.

3.    public class Commander {

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

5.                               // more code here

6.          }

7.  }

 

Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains "." (current directory). Which command line correctly runs Commander?

 

A.    java Commander

B.    java com.sun.sjcp.Commander

C.    java com/sun/sjcp/Commander

D.    java -cp com.sun.sjcp Commander

E.    java -cp com/sun/sjcp Commander

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 60

Given:

 

interface DoStuff2 {

float getRange(int low, int high);

}

 

interface DoMore {

float getAvg(int a, int b, int c);

}

 

abstract class DoAbstract implements DoStuff2, DoMore {

}

 

6.   class DoStuff implements DoStuff2 {

7.        public float getRange(int x, int y) {

8.             return 3.14f;

09.    }

10. } 11.

12.  interface DoAll extends DoMore {

13.      float getAvg(int a, int b, int c, int d);

14. }

 

What is the result?

 

A.    The file will compile without error.

B.    Compilation fails. Only line 7 contains an error.

C.    Compilation fails. Only line 12 contains an error.

D.    Compilation fails. Only line 13 contains an error.

E.    Compilation fails. Only lines 7 and 12 contain errors.

F.    Compilation fails. Only lines 7 and 13 contain errors.

G.   Compilation fails. Lines 7, 12, and 13 contain errors.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

 

 


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

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

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

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


📖 Contents 📖