카테고리 없음
OCJP Study 02
Soul-Learner
2013. 12. 26. 12:43
OCJP(Java 6) 기출문제 연습 2(11~20)
PC나 스마트폰에서도 동일하게 실행되므로 장소를 가리지 않고 OCJP(JAVA 6) 국제 자격증을 목표로 학습할 수 있다.
QUESTION 11
Click the Exhibit button.
What is the result?
11. public class Person {
12. String name = "No name";
13. public Person(String nm) { name = nm; }
14. }
15.
16. public class Employee extends Person {
17. String empID = "0000";
18. public Employee(String id) { empID = id; }
19. }
20.
21. public class EmployeeTest {
22. public static void main(String[] args){
23. Employee e = new Employee("4321");
24. System.out.println(e.empID);
25. }
26. }
Click the Exhibit button.
What is the result?
11. public class Person {
12. String name = "No name";
13. public Person(String nm) { name = nm; }
14. }
15.
16. public class Employee extends Person {
17. String empID = "0000";
18. public Employee(String id) { empID = id; }
19. }
20.
21. public class EmployeeTest {
22. public static void main(String[] args){
23. Employee e = new Employee("4321");
24. System.out.println(e.empID);
25. }
26. }
D
Implicit super constructor Person() is undefined. Must explicitly invoke another constructor
QUESTION 12
Given:
1. public class Rainbow {
2. public enum MyColor {
3. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);
4. private final int rgb;
5. MyColor(int rgb) { this.rgb = rgb; }
6. public int getRGB() { return rgb; }
7. };
8. public static void main(String[] args) {
9. //insert code here
10. }
11.}
Which code fragment, inserted at line 19, allows the Rainbow class to compile?
Given:
1. public class Rainbow {
2. public enum MyColor {
3. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);
4. private final int rgb;
5. MyColor(int rgb) { this.rgb = rgb; }
6. public int getRGB() { return rgb; }
7. };
8. public static void main(String[] args) {
9. //insert code here
10. }
11.}
Which code fragment, inserted at line 19, allows the Rainbow class to compile?
B
설명없음
QUESTION 13
Given:
1. public class Mud {
2. //insert code here
3. System.out.println("hi");
4. }
5. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String...[] a) {
How many of the code fragments, inserted independently at line 2, compile?
Given:
1. public class Mud {
2. //insert code here
3. System.out.println("hi");
4. }
5. }
And the following five fragments:
public static void main(String...a) {
public static void main(String.* a) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String...[] a) {
How many of the code fragments, inserted independently at line 2, compile?
D
public static void main(String...a) {
public static void main(String... a) {
public static void main(String[]... a) {
public static void main(String... a) {
public static void main(String[]... a) {
QUESTION 14
Given:
1. class Atom {
2. Atom() { System.out.print("atom "); }
3. }
4. class Rock extends Atom {
5. Rock(String type) { System.out.print(type); }
6. }
7. public class Mountain extends Rock {
8. Mountain() {
9. super("granite ");
10. new Rock("granite ");
11. }
12. public static void main(String[] a) { new Mountain(); }
13.}
What is the result?
Given:
1. class Atom {
2. Atom() { System.out.print("atom "); }
3. }
4. class Rock extends Atom {
5. Rock(String type) { System.out.print(type); }
6. }
7. public class Mountain extends Rock {
8. Mountain() {
9. super("granite ");
10. new Rock("granite ");
11. }
12. public static void main(String[] a) { new Mountain(); }
13.}
What is the result?
F
설명없음
QUESTION 15
Given:
interface TestA { String toString(); }
public class Test {
public static void main(String[] args) {
System.out.println(new TestA() {
public String toString() { return "test"; }
});
}
}
What is the result?
Given:
interface TestA { String toString(); }
public class Test {
public static void main(String[] args) {
System.out.println(new TestA() {
public String toString() { return "test"; }
});
}
}
What is the result?
A
설명없음
QUESTION 16
Given:
1. public static void parse(String str) {
2. try {
3. float f = Float.parseFloat(str);
4. } catch (NumberFormatException nfe) {
5. f = 0;
6. } finally {
7. System.out.println(f);
8. }
9. }
10. public static void main(String[] args) {
11. parse("invalid");
12. }
What is the result?
Given:
1. public static void parse(String str) {
2. try {
3. float f = Float.parseFloat(str);
4. } catch (NumberFormatException nfe) {
5. f = 0;
6. } finally {
7. System.out.println(f);
8. }
9. }
10. public static void main(String[] args) {
11. parse("invalid");
12. }
What is the result?
B
f cannot be resolved in line 5 and 7
QUESTION 17
Given:
1. public class Blip {
2. protected int blipvert(int x) { return 0; }
3. }
4. class Vert extends Blip {
5. // insert code here
6. }
Which five methods, inserted independently at line 5, will compile? (Choose five.)
Given:
1. public class Blip {
2. protected int blipvert(int x) { return 0; }
3. }
4. class Vert extends Blip {
5. // insert code here
6. }
Which five methods, inserted independently at line 5, will compile? (Choose five.)
A,C,E,F,G
private int blipvert(int x) { return 0; }
Cannot reduce the visibility of the inherited method from Blip
protected long blipvert(int x) { return 0; }
The return type is incompatible with Blip.blipvert(int)
Cannot reduce the visibility of the inherited method from Blip
protected long blipvert(int x) { return 0; }
The return type is incompatible with Blip.blipvert(int)
QUESTION 18
Given:
1. class Super {
2. private int a;
3. protected Super(int a) { this.a = a; }
4. }
11. class Sub extends Super {
12. public Sub(int a) { super(a); }
13. public Sub() { this.a = 5; }
14. }
Which two, independently, will allow Sub to compile? (Choose two.)
Given:
1. class Super {
2. private int a;
3. protected Super(int a) { this.a = a; }
4. }
11. class Sub extends Super {
12. public Sub(int a) { super(a); }
13. public Sub() { this.a = 5; }
14. }
Which two, independently, will allow Sub to compile? (Choose two.)
C,D
설명없음
QUESTION 19
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?
D
설명없음
QUESTION 20
Given:
1. package test;
2.
3. class Target {
4. public String name = "hello";
5. }
What can directly access and change the value of the variable name?
Given:
1. package test;
2.
3. class Target {
4. public String name = "hello";
5. }
What can directly access and change the value of the variable name?
C
설명없음