728x90
728x170
[1Z0-808][OCAJP] Dump 문제 81~90
문제 81
Q. Which two class definitions fail to compile? (Choose two.) | |
A | abstract class A3 { private static int i; public void doStuff() {} public A3() {} } |
B | final class A1 { public A1() {} } |
C | public class A2 { private static int i; private A2() {} } |
D | class A4 { protected static final int i; private void doStuff() {} } |
E | final abstract class A5 { protected static int i; void doStuff() {} abstract void doIt(); } |
정답
D, E
해설/결과
- D : final 필드는 반드시 초기화 되어야 한다. (오답)
- E : 추상 클래스는 final 클래스가 될 수 없다. (오답)
문제 82
Given :
public class Test {
public static final int MIN = 1;
public static void main(String[] args) {
int x = args.length;
if (checkLimit(x)) { // line n1
System.out.println("Java SE");
} else {
System.out.println("Java EE");
}
}
public static boolean checkLimit(int x) {
return (x >= MIN) ? true : false;
}
}
And give the commands:
javac Test.java
java Test
Q. What is the result? | |
A | Java SE |
B | A NullPointerException is thrown at runtime. |
C | Compilation fails at line n1. |
D | Java EE |
정답
D
해설/결과
- int x = args[0].length; 으로 할 경우, "Java SE"가 출력된다.
문제 83
Given :
public class App {
String myStr = "7007";
public void doStuff(String str) {
int myNum = 0;
try {
String myStr = str;
myNum = Integer.parseInt(myStr);
} catch (NumberFormatException ne) {
System.err.println("Error");
}
System.out.println(
"myStr: " + myStr + ", myNum: " + myNum);
}
public static void main(String[] args) {
App obj = new App();
obj.doStuff("9009");
}
}
Q. Which statement is true about Java byte code? | |
A | myStr: 7007, myNum: 9009 |
B | myStr: 9009, myNum: 9009 |
C | myStr: 7007, myNum: 7007 |
D | Compilation fails. |
정답
A
해설/결과
문제 84
Q. Which two are benefits of polymorphism? (Choose two.) | |
A | Faster code at runtime |
B | More efficient code at runtime |
C | More dynamic code at runtime |
D | More flexible and reusuable code |
E | Code that is protected from extension by other classes |
정답
C, D
해설/결과
문제 85
Given :
public class Test {
int x, y;
public Test(int x, int y) {
initialize(x, y);
}
public void initialize(int x, int y) {
this.x = x * x;
this.y = y * y;
}
public static void main(String[] args) {
int x = 3, y = 5;
Test obj = new Test(x, y);
System.out.println(x + " " + y);
}
}
Q. What is the result? | |
A | Compilatin fails. |
B | 0 0 |
C | 9 25 |
D | 3 5 |
정답
D
해설/결과
문제 86
Q. Which three statements are true about the structure of Java class? (Choose three.) | |
A | A class can have overloaded static methods. |
B | A method can have the same name as a field. |
C | The methods are mandatory components of a class. |
D | A class can have only one private constructor. |
E | A public class must have a main method. |
F | The fields need not be initialized before use. |
정답
A, B, F
해설/결과
- A : 1개의 클래스는 중첩된(Overloaded) 정적 메서드를 포함할 수 있다.
- B : 메서드는 필드와 똑같은 이름을 갖을 수 있다.
- F : 필드는 사용되기 전에 초기화 될 필요는 없다.
문제 87
Given the code following class :
public class Rectangle {
private double length;
private double height;
private double area;
public void setLength(double length) {
this.length = length;
}
public void setHeight(double height) {
this.height = height;
}
public void setArea() {
area = length * height;
}
Q. Which two changes would encapsulate this class and ensure that the area field is always equal to length* height whenever the Rectangle class is used? | |
A | Change the area field to public. |
B | Call the setArea method at the beginning of the setHeight method. |
C | Call the setArea method at the beginning of the setLength method. |
D | Change the setArea method to private. |
E | Call the setArea method at the end of the setLength method. |
F | Call the setArea method at the end of the setHeight method. |
정답
E, F
해설/결과
문제 88
Given :
public class FieldInit {
char c;
boolean b;
float f;
void printAll() {
System.out.println("c = " + c);
System.out.println("b = " + b);
System.out.println("f = " + f);
}
public static void main(String[] args) {
FieldInit f = new FieldInit();
f.printAll();
}
}
Q. What is the result? | |
A | c = b = false f = 0.0 |
B | c = null b = true f = 0.0 |
C | c = 0 b = false f = 0.0f |
D | c = null b = false f = 0.0F |
정답
A
해설/결과
문제 89
Q. Which one of the following code examples uses valid Java syntax? |
|
A | public class Boat { public static void main(String[] args) { System.out.println("I Float."); } } |
B | public class Cake { public static void main(String[]) { System.out.println("Chocolate"); } } |
C | public class Dog { public void main(String[] args) { System.out.println("Squirrel"); } } |
D | public class Bank { public static void main(String() args) { System.out.println("Earn interest."); } } |
정답
A
해설/결과
- C : main 메서드는 정적(static)이어야 하므로 오답
문제 90
Q. Which three statements are true about exception handling? (Choose three.) | |
A | The parameter in a catch block is of Throwable type. |
B | All subclasses of the RuntimeException class are recoverable. |
C | Only unchecked exceptions can be thrown. |
D | All subclasses of the Exception class except the RuntimeException class are checked exceptions. |
E | All subclasses of the Error class are checked exceptions and are recoverable. |
F | All subclasses of the RuntimeException class must be caught or declared to be thrown. |
정답
A, B, D
해설/결과
- A : catch 블럭에 있는 매개변수(parameter)는 Throwable 타입이다. (정답)
- B : RuntimeException 클래스의 모든 서브 클래스는 복구되어질(recoveable) 수 있다. (정답)
- C : 오직 확인되지 않은 예외만 던져질(thrown) 수 있다. (오답)
- D : 예외 클래스의 모든 서브 클래스는 확인된 예외이며 복구되어질 수 있다. (정답)
- E : 에러 클래스의 모든 서브 클래스는 확인된 예외이며 복구되어질 수 있다. (오답)
- 에러는 예외가 아니다.
- F : RuntimeException 클래스의 모든 부분 클래스는 던져지기(thrown) 위해 반드시 잡히거나(caught) 선언되어야 한다. (오답)
728x90
그리드형(광고전용)
'Certificate > OCAJP' 카테고리의 다른 글
[1Z0-808][OCAJP] Dump 문제 91~100 (0) | 2022.01.14 |
---|---|
[1Z0-808][OCAJP] Dump 문제 71~80 (0) | 2022.01.11 |
[1Z0-808][OCAJP] Dump 문제 61~70 (0) | 2022.01.09 |
[1Z0-808][OCAJP] Dump 문제 51~60 (0) | 2022.01.07 |
[1Z0-808][OCAJP] Dump 문제 41~50 (0) | 2022.01.07 |
[1Z0-808][OCAJP] Dump 문제 31~40 (0) | 2022.01.04 |
[1Z0-808][OCAJP] Dump 문제 21~30 (0) | 2022.01.02 |
[1Z0-808][OCAJP] Dump 문제 11~20 (0) | 2022.01.02 |