Given 11 public static void parseString str 12 try 13 float f

Given 11 public static void parsestring str 12 try 13

This preview shows page 16 - 20 out of 120 pages.

Question 27Given:11. public static void parse(String str) {12. try {13. float f= Float.parseFloat(str);14. } catch (NumberFormatException nfe) {15. f= 0;16. } finally {17. System.out.println(f);18. }19. }20. public static void main(String[] args) {21. parse(”invalid”);22. }What is the result? A. 0.0B. Compilation fails. C. A ParseException is thrown by the parse method at runtime.
Background image
D. A NumberFormatException is thrown by the parse method atruntime.Answer: B Question 28Click the Exhibit button.1. public class Test {2. int x= 12;3. public void method(int x) {4. x+=x;5. System.out.println(x);6. }7. }Given:34. Test t = new Test();35. t.method(5);What is the output from line 5 of the Test class? Question 28Given:55. int []x= {1, 2,3,4, 5};56.int y[] =x;57. System.out.println(y[2]);Which is true? Question 30 Given:35.String #name = “Jane Doe”;36.int$age=24;
Background image
38. double~temp = 37.5;Which two are true? (Choose two.) A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD Question 31Which two code fragments correctly create and initialize a static arrayof int elements? (Choose two.) Question 32Given:11. public class Ball {12. public enum Color { RED, GREEN, BLUE };13. public void foo() {14. // insert code here15. { System.out.println(c); }16. }17. }Which code inserted at line 14 causes the foo method to print RED,GREEN, and BLUE?
Background image
Question 33Given:10. public class Fabric 11. public enum Color {12. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);13. private final int rgb;14. Color( int rgb) { this.rgb = rgb; }15. public int getRGB() { return rgb; }16. };17. public static void main( String[] argv) {18. // insert code here19. }20. }Which two code fragments, inserted independently at line 18, allow theFabric class to compile? (Choose two.)
Background image
Image of page 20

You've reached the end of your free preview.

Want to read all 120 pages?

  • Summer '17
  • Madrid Metro, Metropolitana di Napoli, Osaka Municipal Subway, public interface Status

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture