QUESTION 21
Given:
5. class Building { }
6. public class Barn extends Building {
7. public static void main(String[] args) {
8. Building build1 = new Building();
9. Barn barn1 = new Barn();
10. Barn barn2 = (Barn) build1;
11. Object obj1 = (Object) build1;
12. String str1 = (String) build1;
13. Building build2 = (Building) barn1;
14. }
15. }
Which is true?
A. If line 10 is removed, the compilation succeeds.
B. If line 11 is removed, the compilation succeeds.
C. If line 12 is removed, the compilation succeeds.
D. If line 13 is removed, the compilation succeeds.
E. More than one line must be removed for compilation to succeed.
Correct Answer: C Section: All Explanation
Explanation/Reference:
Cannot cast from Building to String
QUESTION 22
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?
A. Looser coupling
B. Tighter coupling
C. Lower cohesion
D. Higher cohesion
E. Weaker encapsulation
F. Stronger encapsulation
Correct Answer: A Section: All Explanation
Explanation/Reference:
QUESTION 23
Given:
21. class Money {
22. private String country = "Canada";
23. public String getC() { return country; }
24. }
25. class Yen extends Money {
26. public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29. public String getC(int x) { return super.getC(); }
30. public static void main(String[] args) {
31. System.out.print(new Yen().getC() + " " + new Euro().getC());
32. }
33. }
What is the result?
A. Canada
B. null Canada
C. Canada null
D. Canada Canada
E. Compilation fails due to an error on line 26.
F. Compilation fails due to an error on line 29.
Correct Answer: E Section: All Explanation
Explanation/Reference:
The field Money.country is not visible
QUESTION 24
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:
13. import java.io.*;
14. class Food implements Serializable {int good = 3;}
15. class Fruit extends Food {int juice = 5;}
16. public class Banana extends Fruit {
17. int yellow = 4;
18. public static void main(String [] args) {
19. Banana b = new Banana(); Banana b2 = new Banana();
20. b.serializeBanana(b); // assume correct serialization
21. b2 = b.deserializeBanana(); // assume correct
22. System.out.println("restore "+b2.yellow+ b2.juice+b2.good);
24. }
25. // more Banana methods go here
50. }
What is the result?
A. restore 400
B. restore 403
C. restore 453
D. Compilation fails.
E. An exception is thrown at runtime.
Correct Answer: C Section: All Explanation
Explanation/Reference:
QUESTION 25
Given a valid DateFormat object named df, and
16. Date d = new Date(0L);
17. String ds = "December 15, 2004";
18. //insert code here
What updates d's value with the date represented by ds?
A. d = df.parse(ds);
B. d = df.getDate(ds);
C. try {
d = df.parse(ds);
} catch(ParseException e) { };
D. try {
d = df.getDate(ds);
} catch(ParseException e) { };
Correct Answer: C Section: All Explanation
Explanation/Reference:
QUESTION 26
Given:
11. double input = 314159.26;
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);
13. String b;
14. //insert code here
Which code, inserted at line 14, sets the value of b to 314.159,26?
A. b = nf.parse( input );
B. b = nf.format( input );
C. b = nf.equals( input );
D. b = nf.parseObject( input );
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 27
Given:
public class TestString1 {
public static void main(String[] args) { String str = "420";
str += 42; System.out.print(str);
}
}
What is the output?
A. 42
B. 420
C. 462
D. 42042
E. Compilation fails.
F. An exception is thrown at runtime.
Correct Answer: D Section: All Explanation
Explanation/Reference:
QUESTION 28
Which capability exists only in java.io.FileWriter?
A. Closing an open stream.
B. Flushing an open stream.
C. Writing to an open stream.
D. Writing a line separator to an open stream.
Correct Answer: D Section: All Explanation
Explanation/Reference:
QUESTION 29
Given that the current directory is empty, and that the user has read and write permissions, and the following:
import java.io.*;
public class DOS {
public static void main(String[] args) { File dir = new File("dir"); dir.mkdir();
File f1 = new File(dir, "f1.txt");
try {
f1.createNewFile();
} catch (IOException e) { ; } File newDir = new File("newDir"); dir.renameTo(newDir);
}
}
Which statement is true?
A. Compilation fails.
B. The file system has a new empty directory named dir.
C. The file system has a new empty directory named newDir.
D. The file system has a directory named dir, containing a file f1.txt.
E. The file system has a directory named newDir, containing a file f1.txt.
Correct Answer: E Section: All Explanation
Explanation/Reference:
QUESTION 30
Given:
static void test() throws RuntimeException {
try {
System.out.print("test ");
throw new RuntimeException();
}
catch (Exception ex) { System.out.print("exception "); }
}
public static void main(String[] args) {
try { test(); }
catch (RuntimeException ex) { System.out.print("runtime "); } System.out.print("end ");
}
What is the result?
A. test end
B. Compilation fails.
C. test runtime end
D. test exception end
E. A Throwable is thrown by main at runtime.
Correct Answer: D Section: All Explanation
Explanation/Reference:
Source from : Oracle.Exactexams.1z0-851.v2013-11-27.by.SomeBody ().pdf
'Certificate > OCAJP' 카테고리의 다른 글
[1Z0-851B] Question 11~20 (0) | 2017.08.11 |
---|---|
[1Z0-851B] Question 01~10 (0) | 2017.08.11 |
[1Z0-851A] Question 51~60 (0) | 2017.08.05 |
[1Z0-851A] Question 41~50 (0) | 2017.08.05 |
[1Z0-851A] Question 31~40 (0) | 2017.08.05 |
[1Z0-851A] Question 11~20 (0) | 2017.08.05 |
[1Z0-851A] Question 01~10 (0) | 2017.08.04 |
OCJP Dumps (0) | 2017.07.12 |