QUESTION 11
Given:
1. public class Hi {
2. void m1() { }
3. protected void() m2 { }
04. } 05.
6. class Lois extends Hi {
7. // insert code here
08. }
Which four code fragments, inserted independently at line 7, will compile? (Choose four.)
A. public void m1() { }
B. protected void m1() { }
C. private void m1() { }
D. void m2() { }
E. public void m2() { }
F. protected void m2() { }
G. private void m2() { }
Correct Answer: ABEF Section: All Explanation
Explanation/Reference:
QUESTION 12
Which four statements are true? (Choose four.)
A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance.
C. Has-a relationships can be implemented using instance variables.
D. Is-a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements keyword.
F. The relationship between Movie and Actress is an example of an is-a relationship.
G. An array or a collection can be used to implement a one-to-many has-a relationship.
Correct Answer: CDEG Section: All Explanation
Explanation/Reference:
QUESTION 13
Given:
public class Hello { String title; int value;
public Hello() { title += " World";
}
public Hello(int value) { this.value = value; title = "Hello"; Hello();
}
}
and:
Hello c = new Hello(5); System.out.println(c.title);
What is the result?
A. Hello
B. Hello World
C. Compilation fails.
D. Hello World 5
E. The code runs with no output.
F. An exception is thrown at runtime.
Correct Answer: C Section: All Explanation
Explanation/Reference:
The method Hello() is undefined for type Hello. If you want this code to compile there should be new Hello();
QUESTION 14
Given:
package geometry;
public class Hypotenuse {
public InnerTriangle it = new InnerTriangle();
class InnerTriangle { public int base; public int height;
}
}
Which statement is true about the class of an object that can reference the variable base?
A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.
Correct Answer: C Section: All Explanation
Explanation/Reference:
QUESTION 15
Given:
interface Data { public void load(); }
abstract class Info { public abstract void load(); }
Which class correctly uses the Data interface and Info class?
A. public class Employee extends Info implements Data {
public void load() { /*do something*/ }
}
B. public class Employee implements Info extends Data {
public void load() { /*do something*/ }
}
C. public class Employee extends Info implements Data {
public void load(){ /*do something*/ }
public void Info.load(){ /*do something*/ }
}
D. public class Employee implements Info extends Data { public void Data.load(){ /*do something*/ } public void load(){ /*do something*/ }
}
E. public class Employee implements Info extends Data {
public void load(){ /*do something*/ }
public void Info.load(){ /*do something*/ }
}
F. public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ }
}
Correct Answer: A Section: All Explanation
Explanation/Reference:
QUESTION 16
Given:
class Alligator {
public static void main(String[] args) {
int[] x[] = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
int[][] y = x; System.out.println(y[2][1]);
}
}
What is the result?
A. 2
B. 3
C. 4
D. 6
E. 7
F. Compilation fails.
Correct Answer: E Section: All Explanation
Explanation/Reference:
QUESTION 17
Given:
abstract class C1 {
public C1() { System.out.print(1); }
}
class C2 extends C1 {
public C2() { System.out.print(2); }
}
class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}
What is the result?
A. 3
B. 23
C. 32
D. 123
E. 321
F. Compilation fails.
G. An exception is thrown at runtime.
Correct Answer: D Section: All Explanation
Explanation/Reference:
QUESTION 18
Given:
class One {
public One foo() {
return this;
}
}
class Two extends One {
public One foo() {
return this;
}
}
class Three extends Two {
// insert method here
}
Which two methods, inserted individually, correctly complete the Three class? (Choose two.)
A. public void foo() {}
B. public int foo() { return 3; }
C. public Two foo() { return this; }
D. public One foo() { return this; }
E. public Object foo() { return this; }
Correct Answer: CD Section: All Explanation
Explanation/Reference:
QUESTION 19
Which two classes correctly implement both the java.lang.Runnable and the java.lang.Cloneable
interfaces? (Choose two.)
A. public class Session implements Runnable, Cloneable {
public void run();
public Object clone();
}
B. public class Session extends Runnable, Cloneable { public void run() { /* do something */ } public Object clone() { /* make a copy */ }
}
C. public class Session implements Runnable, Cloneable {
public void run() { /* do something */ }
public Object clone() { /* make a copy */ }
}
D. public abstract class Session
implements Runnable, Cloneable {
public void run() { /* do something */ }
public Object clone() { /*make a copy */ }
}
E. public class Session implements Runnable, implements Cloneable {
public void run() { /* do something */ }
public Object clone() { /* make a copy */ }
}
Correct Answer: CD Section: All Explanation
Explanation/Reference:
QUESTION 20
Given:
public interface A { public void m1(); }
class B implements A { }
class C implements A { public void m1() { } } class D implements A { public void m1(int x) { } } abstract class E implements A { }
abstract class F implements A { public void m1() { } }
abstract class G implements A { public void m1(int x) { } }
What is the result?
A. Compilation succeeds.
B. Exactly one class does NOT compile.
C. Exactly two classes do NOT compile.
D. Exactly four classes do NOT compile.
E. Exactly three classes do NOT compile.
Correct Answer: C Section: All Explanation
Explanation/Reference:
Source from : Oracle.Exactexams.1z0-851.v2013-11-27.by.SomeBody ().pdf
'Certificate > OCAJP' 카테고리의 다른 글
[1Z0-851C] Question 51~60 (0) | 2017.08.12 |
---|---|
[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 01~10 (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 |