QUESTION 31
Given:
public class Score implements Comparable<Score> {
private int wins, losses;
public Score(int w, int l) { wins = w; losses = l; }
public int getWins() { return wins; } public int getLosses() { return losses; } public String toString() {
return "<" + wins + "," + losses + ">";
}
// insert code here
}
Which method will complete this class?
A. public int compareTo(Object o){/*more code here*/}
B. public int compareTo(Score other){/*more code here*/}
C. public int compare(Score s1,Score s2){/*more code here*/}
D. public int compare(Object o1,Object o2){/*more code here*/}
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 32
A company has a business application that provides its users with many different reports: receivables reports, payables reports, revenue projects, and so on. The company has just purchased some new, state- of-the-art, wireless printers, and a programmer has been assigned the task of enhancing all of the reports to use not only the company's old printers, but the new wireless printers as well. When the programmer starts looking into the application, the programmer discovers that because of the design of the application, it is necessary to make changes to each report to support the new printers.Which two design concepts most likely explain this situation? (Choose two.)
A. Inheritance
B. Low cohesion
C. Tight coupling
D. High cohesion
E. Loose coupling
F. Object immutability
Correct Answer: BC Section: All Explanation
Explanation/Reference:
QUESTION 33
Given:
10. public class SuperCalc {
11. protected static int multiply(int a, int b) { return a * b;}
12. }
and:
20. public class SubCalc extends SuperCalc{
21. public static int multiply(int a, int b) {
22. int c = super.multiply(a, b);
23. return c;
24. }
25. }
and:
30. SubCalc sc = new SubCalc ();
31. System.out.println(sc.multiply(3,4));
32. System.out.println(SubCalc.multiply(2,2));
What is the result?
A. 12
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 21.
E. Compilation fails because of an error in line 22.
F. Compilation fails because of an error in line 31.
Correct Answer: E Section: All Explanation
Explanation/Reference:
Cannot use super in a static context
QUESTION 34
Given:
class Foo {
public int a = 3;
public void addFive() { a += 5; System.out.print("f "); }
}
class Bar extends Foo {
public int a = 8;
public void addFive() { this.a += 5; System.out.print("b " ); }
}
Invoked with:
Foo f = new Bar(); f.addFive(); System.out.println(f.a);
What is the result?
A. b 3
B. b 8
C. b 13
D. f 3
E. f 8
F. f 13
G. Compilation fails.
H. An exception is thrown at runtime.
Correct Answer: A Section: All Explanation
Explanation/Reference:
QUESTION 35
Given:
22. StringBuilder sb1 = new StringBuilder("123");
23. String s1 = "123";
24. // insert code here
25. System.out.println(sb1 + " " + s1);
Which code fragment, inserted at line 24, outputs "123abc 123abc"?
A. sb1.append("abc"); s1.append("abc");
B. sb1.append("abc"); s1.concat("abc");
C. sb1.concat("abc"); s1.append("abc");
D. sb1.concat("abc"); s1.concat("abc");
E. sb1.append("abc"); s1 = s1.concat("abc");
F. sb1.concat("abc"); s1 = s1.concat("abc");
G. sb1.append("abc"); s1 = s1 + s1.concat("abc");
H. sb1.concat("abc"); s1 = s1 + s1.concat("abc");
Correct Answer: E Section: All Explanation
Explanation/Reference:
QUESTION 36
Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?
1. import java.io.*;
2. public class Foo implements Serializable {
3. public int x, y;
4. public Foo(int x, int y){
5. this.x = x; this.y = y;
06. } 07.
8. private void writeObject(ObjectOutputStream s)
9. throws IOException{
10. s.writeInt(x); s.writeInt(y);
11. } 12.
13. private void readObject(ObjectInputStream s)
14. throws IOException, ClassNotFoundException {
15. //insert code here
16. }
17. }
A. s.defaultReadObject();
B. this = s.defaultReadObject();
C. y = s.readInt(); x = s.readInt();
D. x = s.readInt(); y = s.readInt();
Correct Answer: D Section: All Explanation
Explanation/Reference:
QUESTION 37
Given:
1. public class LineUp {
2. public static void main(String[] args) {
03. double d = 12.345;
04. // insert code here
05. }
06. }
Which code fragment, inserted at line 4, produces the output | 12.345|?
A. System.out.printf("|%7d| \n", d);
B. System.out.printf("|%7f| \n", d);
C. System.out.printf("|%3.7d| \n", d);
D. System.out.printf("|%3.7f| \n", d);
E. System.out.printf("|%7.3d| \n", d);
F. System.out.printf("|%7.3f| \n", d);
Correct Answer: F Section: All Explanation
Explanation/Reference:
QUESTION 38
Given:
11. public class Test {
12. public static void main(String [] args) {
13. int x = 5;
14. boolean b1 = true;
15. boolean b2 = false; 16.
17. if ((x == 4) && !b2 )
18. System.out.print("1 ");
19. System.out.print("2 ");
20. if ((b2 = true) && b1 )
21. System.out.print("3 ");
22. }
23. }
What is the result?
A. 2
B. 3
C. 1 2
D. 2 3
E. 1 2 3
F. Compilation fails.
G. An exception is thrown at runtime.
Correct Answer: D Section: All Explanation
Explanation/Reference:
QUESTION 39
Given:
10. interface Foo {}
11. class Alpha implements Foo {}
12. class Beta extends Alpha {}
13. class Delta extends Beta {
14. public static void main( String[] args ) {
15. Beta x = new Beta();
16. //insert code here
17. }
18. }
Which code, inserted at line 16, will cause a java.lang.ClassCastException?
A. Alpha a = x;
B. Foo f = (Delta)x;
C. Foo f = (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 40
Given:
public void go() { String o = ""; z:
for(int x = 0; x < 3; x++) {
for(int y = 0; y < 2; y++) {
if(x==1) break;
if(x==2 && y==1) break z; o = o + x + y;
}
}
System.out.println(o);
}
What is the result when the go() method is invoked?
A. 00
B. 0001
C. 000120
D. 00012021
E. Compilation fails.
F. An exception is thrown at runtime.
Correct Answer: C 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 21~30 (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 |