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

QUESTION 1

Given:

 

import java.util.Date;

import java.text.DateFormat;

 

21.  DateFormat df;

22.  Date date = new Date();

23.  //insert code here

24.  String s = df.format(date);

 

Which code fragment, inserted at line 23, allows the code to compile?

 

A.    df = new DateFormat();

B.    df = Date.getFormat();

C.    df = date.getFormat();

D.    df = DateFormat.getFormat();

E.    df = DateFormat.getInstance();

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 2

Given:

 

public class BuildStuff {

public static void main(String[] args) { Boolean test = new Boolean(true); Integer x = 343;

Integer y = new BuildStuff().go(test, x); System.out.println(y);

}

int go(Boolean b, int i) { if(b) return (i/7); return (i/49);

}

}

 

What is the result?

 

        A.    7

 B.    49

 C.  343

D.    Compilation fails.

E.    An exception is thrown at runtime.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

 

 QUESTION 3 

 Given:

 

import java.io.*;

 

public class Forest implements Serializable {

private Tree tree = new Tree();

 

public static void main(String [] args) { Forest f = new Forest();

try {

 

FileOutputStream fs = new FileOutputStream("Forest.ser"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(f); os.close();

} catch (Exception ex) { ex.printStackTrace(); }

}

}

 

class Tree { }

 

What is the result?

 

A.    Compilation fails.

B.    An exception is thrown at runtime.

C.    An instance of Forest is serialized.

D.    An instance of Forest and an instance of Tree are both serialized.

 

Correct Answer: B Section: All Explanation

 

Explanation/Reference:

java.io.NotSerializableException: Tree

at java.io.ObjectOutputStream.writeObject0(Unknown Source)

at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source) at java.io.ObjectOutputStream.writeSerialData(Unknown Source)

at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) at java.io.ObjectOutputStream.writeObject0(Unknown Source)

at java.io.ObjectOutputStream.writeObject(Unknown Source) at Forest.main(Forest.java:9)

 

 

QUESTION 4

Given:

 

01. import java.io.*; 02.

3.   public class Talk {

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

5.             Console c = new Console();

6.             String pw;

7.             System.out.print("password: ");

8.             pw = c.readLine();

9.             System.out.println("got " + pw);

10.    }

11. }

 

If the user types the password aiko when prompted, what is the  result?

 

A.    password: got

B.    password: got aiko

C.    password: aiko got aiko

D.    An exception is thrown at runtime.

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

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

Console doesn't have constructor. To get instance of Console you have to invoke: System.console()

 

 

QUESTION 5

Given:

 

11.  String test = "Test A. Test B. Test C.";

12.  // insert code here

13.  String[] result = test.split(regex);

 

Which regular expression, inserted at line 12, correctly splits test into "Test A", "Test B", and "Test C"?

 

A.    String regex = "";

B.    String regex = " ";

C.    String regex = ".*";

D.    String regex = "\\s";

E.    String regex = "\\.\\s*";

F.    String regex = \\w[ \.] +;

 

Correct Answer: E Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 6

Given:

 

1.   interface A { public void aMethod(); }

2.   interface B { public void bMethod(); }

3.   interface C extends A,B { public void cMethod(); }

4.   class D implements B {

5.   public void bMethod(){}

06. }

7.   class E extends D implements C {

8.   public void aMethod(){}

9.   public void bMethod(){}

10.  public void cMethod(){}

11. }

 

What is the result?

 

A.    Compilation fails because of an error in line 3.

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

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

D.    If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.

E.    If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.

F.    If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

 

Correct Answer: F Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 7

Given:

 

public class SimpleCalc { public value;

public void calculate() { value += 7; }

}

 

and:

 

public class MultiCalc extends SimpleCalc { public void calculate() { value -= 3; } public void calculate(int multiplier) {

calculate(); super.calculate(); value *= multiplier;

}

public statuc void main(String[] args) { MultiCalc calculator = new MultiCalc(); calculator.calculate(2);

System.out.println("Value is: " + calculator.value);

}

}

 

What is the result?

 

A.    Value is: 8

B.    Compilation fails.

C.    Value is: 12

D.    Value is: -12

E.    The code runs with no output.

F.    An exception is thrown at runtime.

 

Correct Answer: A Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 8

Given:

 

public class Base {

public static final String FOO = "foo";

 

public static void main(String[] args) { Base b = new Base();

Sub s = new Sub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO);


 

System.out.print(((Base) s).FOO);

}

}

 

class Sub extends Base {

public static final String FOO = "bar";

}

 

What is the result?

 

A.    foofoofoofoofoo

B.    foobarfoobarbar

C.    foobarfoofoofoo

D.    foobarfoobarfoo

E.    barbarbarbarbar

F.    foofoofoobarbar

G.   foofoofoobarfoo

 

Correct Answer: D Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 9

Given:

 

class Mammal {

}

 

class Raccoon extends Mammal { Mammal m = new Mammal();

}

 

class BabyRaccoon extends Mammal {

}

 

Which four statements are true? (Choose four.)

 

A.    Raccoon is-a Mammal.

B.    Raccoon has-a Mammal.

C.    BabyRaccoon is-a Mammal.

D.    BabyRaccoon is-a Raccoon.

E.    BabyRaccoon has-a Mammal.

F.    BabyRaccoon is-a BabyRaccoon.

 

Correct Answer: ABCF Section: All Explanation

 

Explanation/Reference:

 

 

QUESTION 10

Given:

 

interface A { void x(); }

class B implements A { public void x() {} public void y() {} }


 

class C extends B { public void x() {} }

 

and:

 

20.  java.util.List<A> list = new java.util.ArrayList<A>();

21.  list.add(new B());

22.  list.add(new C());

23.  for (A a : list) { 24.    a.x();

25.    a.y();

26. }

 

What is the result?

 

A.    The code runs with no output.

B.    An exception is thrown at runtime.

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

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

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

F.    Compilation fails because of an error in line 25.

 

Correct Answer: F Section: All Explanation

 

Explanation/Reference:

 

 

 

 


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

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

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

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


📖 Contents 📖