Oracle 1z0-851 Exam Practice Questions (P. 3)
- Full Access (260 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
Question #11
Given:
01. public class Rainbow {
02. public enum MyColor {
03. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);
04. private final int rgb;
05. MyColor(int rgb) { this.rgb = rgb; }
06. public int getRGB() { return rgb; }
07. };
08. public static void main(String[] args) {
09. //insert code here
10. }
11. }
Which code fragment, inserted at line 9, allows the Rainbow class to compile?
01. public class Rainbow {
02. public enum MyColor {
03. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);
04. private final int rgb;
05. MyColor(int rgb) { this.rgb = rgb; }
06. public int getRGB() { return rgb; }
07. };
08. public static void main(String[] args) {
09. //insert code here
10. }
11. }
Which code fragment, inserted at line 9, allows the Rainbow class to compile?
- AMyColor skyColor = BLUE;
- BMyColor treeColor = MyColor.GREEN;
- Cif(RED.getRGB() < BLUE.getRGB()) { }
- DCompilation fails due to other error(s) in the code.
- EMyColor purple = new MyColor(0xff00ff);
- FMyColor purple = MyColor.BLUE + MyColor.RED;
Correct Answer:
B
B
send
light_mode
delete
Question #12
Given:
01. public class Mud {
02. //insert code here
03. System.out.println("hi");
04. }
05. }
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?
01. public class Mud {
02. //insert code here
03. System.out.println("hi");
04. }
05. }
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?
- A0
- B1
- C2
- D3
- E4
- F5
Correct Answer:
D
public static void main(String...a) {
public static void main(String... a) {
public static void main(String[]... a) {
D
public static void main(String...a) {
public static void main(String... a) {
public static void main(String[]... a) {
send
light_mode
delete
Question #13
Given:
class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
new Rock("granite ");
}
public static void main(String[] a) { new Mountain(); }
}
What is the result?
class Atom {
Atom() { System.out.print("atom "); }
}
class Rock extends Atom {
Rock(String type) { System.out.print(type); }
}
public class Mountain extends Rock {
Mountain() {
super("granite ");
new Rock("granite ");
}
public static void main(String[] a) { new Mountain(); }
}
What is the result?
- ACompilation fails.
- Batom granite
- Cgranite granite
- Datom granite granite
- EAn exception is thrown at runtime.
- Fatom granite atom granite
Correct Answer:
F
F
send
light_mode
delete
Question #14
Given:
01. interface TestA { String toString(); }
02.
03. public class Test {
04. public static void main(String[] args) {
05. System.out.println(new TestA() {
06. public String toString() { return "test"; }
07. });
08. }
09. }
What is the result?
01. interface TestA { String toString(); }
02.
03. public class Test {
04. public static void main(String[] args) {
05. System.out.println(new TestA() {
06. public String toString() { return "test"; }
07. });
08. }
09. }
What is the result?
- Atest
- Bnull
- CAn exception is thrown at runtime.
- DCompilation fails because of an error in line 1.
- ECompilation fails because of an error in line 5.
- FCompilation fails because of an error in line 6.
Correct Answer:
A
A
send
light_mode
delete
Question #15
Given:
public static void parse(String str) {
try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally {
System.out.println(f);
}
}
public static void main(String[] args) {
parse("invalid");
}
What is the result?
public static void parse(String str) {
try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally {
System.out.println(f);
}
}
public static void main(String[] args) {
parse("invalid");
}
What is the result?
- A0.0
- BCompilation fails.
- CA ParseException is thrown by the parse method at runtime.
- DA NumberFormatException is thrown by the parse method at runtime.
Correct Answer:
B
f cannot be resolved
B
f cannot be resolved
send
light_mode
delete
All Pages