QUESTION 51
Given:
23. Object [] myObjects = {
24. new Integer(12),
25. new String("foo"),
26. new Integer(5),
27. new Boolean(true) 28. };
29. Arrays.sort(myObjects);
30. for(int i=0; i<myObjects.length; i++) {
31. System.out.print(myObjects[i].toString());
32. System.out.print(" ");
33. }
What is the result?
A. Compilation fails due to an error in line 23.
B. Compilation fails due to an error in line 29.
C. A ClassCastException occurs in line 29.
D. A ClassCastException occurs in line 31.
E. The value of all four objects prints in natural order.
Correct Answer: C Section: All Explanation
Explanation/Reference:
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at java.lang.Integer.compareTo(Unknown Source) at java.util.Arrays.mergeSort(Unknown Source) at java.util.Arrays.sort(Unknown Source)
at Barn.main(Barn.java:29)
QUESTION 52
Given a class Repetition:
package utils;
public class Repetition {
public static String twice(String s) { return s + s; }
}
and given another class Demo:
1. public class Demo {
2. public static void main(String[] args) {
3. System.out.println(twice("pizza"));
04. }
05. }
Which code should be inserted at line 1 of Demo.java to compile and run Demo to print "pizzapizza"?
A. import utils.*;
B. static import utils.*;
C. import utils.Repetition.*;
D. static import utils.Repetition.*;
E. import utils.Repetition.twice();
F. import static utils.Repetition.twice;
G. static import utils.Repetition.twice;
Correct Answer: F Section: All Explanation
Explanation/Reference:
QUESTION 53
A UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory / home/bob using the command:
java -classpath /test:/home/bob/downloads/*.jar games.Chess
Bob's CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar
What is a possible location for the Chess.class file?
A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)
Correct Answer: C Section: All Explanation
Explanation/Reference:
QUESTION 54
Given the following directory structure:
bigProject
|--source
| |--Utils.java
|
|--classes
And the following command line invocation:
javac -d classes source/Utils.java
Assume the current directory is bigProject, what is the result?
A. If the compile is successful, Utils.class is added to the source directory.
B. The compiler returns an invalid flag error.
C. If the compile is successful, Utils.class is added to the classes directory.
D. If the compile is successful, Utils.class is added to the bigProject directory.
Correct Answer: C
Section: All
Explanation Explanation/Reference:
QUESTION 55
Given:
package com.company.application;
public class MainClass {
public static void main(String[] args) {}
}
and MainClass exists in the /apps/com/company/application directory. Assume the CLASSPATH environment variable is set to "." (current directory). Which two java commands entered at the command line will run MainClass? (Choose two.)
A. java MainClass if run from the /apps directory
B. java com.company.application.MainClass if run from the /apps directory
C. java -classpath /apps com.company.application.MainClass if run from any directory
D. java -classpath . MainClass if run from the /apps/com/company/application directory
E. java -classpath /apps/com/company/application:. MainClass if run from the /apps
directory
F. java com.company.application.MainClass if run from the /apps/com/company/ application directory
Correct Answer: BC Section: All Explanation
Explanation/Reference:
QUESTION 56
Which statement is true?
A. A class's finalize() method CANNOT be invoked explicitly.
B. super.finalize() is called implicitly by any overriding finalize() method.
C. The finalize() method for a given object is called no more than once by the garbage collector.
D. The order in which finalize() is called on two objects is based on the order in which the two objects became finalizable.
Correct Answer: C Section: All Explanation
Explanation/Reference:
QUESTION 57
Given:
public class Batman {
int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
void go() {
incr(++squares); System.out.println(squares);
}
void incr(int squares) { squares += 10; }
}
What is the result?
A. 81
B. 82
C. 91
D. 92
E. Compilation fails.
F. An exception is thrown at runtime.
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 58
Given:
public class Yippee {
public static void main(String [] args) {
for(int x = 1; x < args.length; x++) { System.out.print(args[x] + " ");
}
}
}
and two separate command line invocations:
java Yippee
java Yippee 1 2 3 4
What is the result?
A. No output is produced. 1 2 3
B. No output is produced. 2 3 4
C. No output is produced. 1 2 3 4
D. An exception is thrown at runtime. 1 2 3
E. An exception is thrown at runtime. 2 3 4
F. An exception is thrown at runtime. 1 2 3 4
Correct Answer: B Section: All Explanation
Explanation/Reference:
QUESTION 59
Given:
public class Pass {
public static void main(String [] args) {
int x = 5;
Pass p = new Pass(); p.doStuff(x);
System.out.print(" main x = " + x);
}
void doStuff(int x) {
System.out.print(" doStuff x = " + x++);
}
}
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuff x = 6 main x = 6
D. doStuff x = 5 main x = 5
E. doStuff x = 5 main x = 6
F. doStuff x = 6 main x = 5
Correct Answer: D Section: All Explanation
Explanation/Reference:
QUESTION 60
Given that c is a reference to a valid java.io.Console object, which two code fragments read a line of text from the console? (Choose two.)
A. String s = c.readLine();
B. char[] c = c.readLine();
C. String s = c.readConsole();
D. char[] c = c.readConsole();
E. String s = c.readLine("%s", "name ");
F. char[] c = c.readLine("%s", "name ");
Correct Answer: AE Section: All Explanation
Explanation/Reference:
Source from : Oracle.Exactexams.1z0-851.v2013-11-27.by.SomeBody ().pdf
'Certificate > OCAJP' 카테고리의 다른 글
[1Z0-851B] Question 31~40 (0) | 2017.08.11 |
---|---|
[1Z0-851B] Question 21~30 (0) | 2017.08.11 |
[1Z0-851B] Question 11~20 (0) | 2017.08.11 |
[1Z0-851B] Question 01~10 (0) | 2017.08.11 |
[1Z0-851A] Question 41~50 (0) | 2017.08.05 |
[1Z0-851A] Question 31~40 (0) | 2017.08.05 |
[1Z0-851A] Question 21~30 (0) | 2017.08.05 |
[1Z0-851A] Question 11~20 (0) | 2017.08.05 |