Question 6 of 260Given: 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?
Correct Answer: B
Question 7 of 260Given: 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?
Correct Answer: D
Question 8 of 260Given: 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?
Correct Answer: F
Question 9 of 260Given: 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?
Correct Answer: A
Question 10 of 260Given: 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?