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

QUESTION 41

Given:

 public static void main(String[] args) {

for (int i = 0; i <= 10; i++) {

if (i > 6) break;

}

System.out.println(i);

}

 

What is the result?

 

A.    6

B.    7

C.    10

D.    11

E.    Compilation fails.

F.    An exception is thrown at runtime.

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

i varaible is not visible.

 

 

QUESTION 42

Given:

 

11. class X { public void foo() { System.out.print("X "); } } 12.

13.  public class SubB extends X {

14.      public void foo() throws RuntimeException {

15.            super.foo();

16.            if (true) throw new RuntimeException();

17.            System.out.print("B ");

18.    }

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

20.            new SubB().foo();

21.    }

22. }


 

What is the result?

 

A.    X, followed by an Exception.

B.    No output, and an Exception is thrown.

C.    Compilation fails due to an error on line 14.

D.    Compilation fails due to an error on line 16.

E.    Compilation fails due to an error on line 17.

F.    X, followed by an Exception, followed by B.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

X Exception in thread "main" java.lang.RuntimeException

at SubB.foo(SubB.java:5) at SubB.main(SubB.java:9)

 

 

QUESTION 43

Given:

 

11.  public void testIfA() {

12.      if (testIfB("True")) {

13.            System.out.println("True");

14.      } else {

15.            System.out.println("Not true");

16.    }

17. }

18.  public Boolean testIfB(String str) {

19.      return Boolean.valueOf(str);

20. }

 

What is the result when method testIfA is invoked?

 

A.    True

B.    Not true

C.    An exception is thrown at runtime.

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

E.    Compilation fails because of an error at line 19.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 44

Which can appropriately be thrown by a programmer using Java SE technology to create a desktop application?

 

A.    ClassCastException

B.    NullPointerException

C.    NoClassDefFoundError

D.    NumberFormatException

E.    ArrayIndexOutOfBoundsException


 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 45

Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)

 

A.  int []x = {1,2,3,4,5};

for(int y = 0; y < 6; y++) System.out.println(x[y]);

B.  static int[] x = {7,6,5,4};

static { x[1] = 8; x[4] = 3; }

C. for(int y = 10; y < 10; y++) doStuff(y);

D. void doOne(int x) { doTwo(x); } void doTwo(int y) { doThree(y); } void doThree(int z) { doTwo(z); }

E. for(int x = 0; x < 1000000000; x++) doStuff(x);

F.   void counter(int i) { counter(++i); }

 

Correct Answer: DF Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 46

Given:

 

4.   public class Tahiti {

5.        Tahiti t; 06.

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

8.             Tahiti t = new Tahiti();

9.             Tahiti t2 = t.go(t);

10.            t2 = null;

11.            // more code here

12.       } 13.

14.      Tahiti go(Tahiti t) {

15.            Tahiti t1 = new Tahiti();

16.            Tahiti t2 = new Tahiti();

17.        t1.t = t2;

18.        t2.t = t1;

19.        t.t = t2;

20.        return t1;

21.    }

22. }

 

When line 11 is reached, how many objects are eligible for garbage collection?

 

A.    0

B.    1

C.    2

D.    3

E.    Compilation fails.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 47

Given:

 

12.  public class Commander {

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

14.            String myProp = /* insert code here */

15.            System.out.println(myProp);

16.    }

17. }

 

and the command line: java -Dprop.custom=gobstopper Commander

 

Which two, placed on line 13, will produce the output gobstopper? (Choose two.)

 

A.    System.load("prop.custom");

B.    System.getenv("prop.custom");

C.    System.property("prop.custom");

D.    System.getProperty("prop.custom");

E.    System.getProperties().getProperty("prop.custom");

 

Correct Answer: DE Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 48

Given:

 

public class ItemTest {

private final int id;

 

public ItemTest(int id) {

this.id = id;

}

 

public void updateId(int newId) { id = newId;

}

 

public static void main(String[] args) { ItemTest fa = new ItemTest(42); fa.updateId(69); System.out.println(fa.id);

}

}

 

What is the result?

 

A.    Compilation fails.

B.    An exception is thrown at runtime.

C.    The attribute id in the ItemTest object remains unchanged.

D.    The attribute id in the ItemTest object is modified to the new value.

E.    A new ItemTest object is created with the preferred value in the id attribute.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

The final field ItemTest.id cannot be assigned

 

 

QUESTION 49

A developer is creating a class Book, that needs to access class Paper. The Paper class is deployed in a JAR named myLib.jar. Which three, taken independently, will allow the developer to use the Paper class while compiling the Book class? (Choose three.)

 

A.    The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar.

B.    The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar..

C.    The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/ myLib.jar/Paper.class.

D.    The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/ myLib.jar.

E.    The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - cp /foo/myLib.jar/ Paper Book.java.

F.    The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d /foo/myLib.jar Book.java

G.   The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - classpath /foo/ myLib.jar Book.java

 

Correct Answer: BDG Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 50

Click the Exhibit button.

 

class Foo {

private int x;

public Foo( int x ){ this.x = x;}

public void setX( int x ) { this.x = x; }

public int getX(){ return x;}

}

 

public class Gamma {

 

static Foo fooBar(Foo foo) { foo = new Foo(100); return foo;

}

 

public static void main(String[] args) { Foo foo = new Foo( 300 ); System.out.println( foo.getX() + "-");

 

Foo fooFoo = fooBar(foo); System.out.println(foo.getX() + "-");


 

System.out.println(fooFoo.getX() + "-");

 

foo = fooBar( fooFoo); System.out.println( foo.getX() + "-"); System.out.println(fooFoo.getX());

}

}

 

What is the output of the program shown in the  exhibit?

 

A.  300-100-100-100-100

B.  300-300-100-100-100

C. 300-300-300-100-100

D. 300-300-300-300-100

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 

 

 


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

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

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

[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
[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
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️


📖 Contents 📖