Click the Exhibit button 1 public class Test 2 3 public static void mainString

Click the exhibit button 1 public class test 2 3

This preview shows page 29 - 32 out of 101 pages.

Question 66Click the Exhibit button.1. public class Test {2.3. public static void main(String [] args) {4. boolean assert = true;5. if(assert) {6. System.out.println(”assert is true”);7. }8. }9.10. }Given:javac -source 1.3 Test.javaWhat is the result? A. Compilation fails.B. Compilation succeeds with errors.C. Compilation succeeds with warnings.D. Compilation succeeds without warnings or errors.Answer: C Question 67Given:23.int z=5;24.25. public void stuff1(int x) {26. assert (x> 0);27. switch(x) {28. case 2: x= 3;29. default: assert false; } }30.31. private void stuff2(int y) { assert (y < 0); }32.33. private void stuff3() { assert (stuff4O); }34.35. private boolean stuff4() { z = 6; return false; }Which is true?
Image of page 29
Question 68Click the Exhibit button.SomeException:1. public class SomeException {2. }Class A:1. public class A {2. public void doSomething() { }3. }Class B:1. public class B extends A {2. public void doSomething() throws SomeException { }3. }Which is true about the two classes? Question 69Click the Exhibit button.Class TestException1. public class TestException extends Exception {2. }Class A:1. public class A {2.3. public String sayHello(String name) throws TestException {4.5. if(name == null) {6. throw new TestException();7. }8.9. return “Hello “+ name;10. }11.12. }A programmer wants to use this code in an application:45. A a=new A();46. System.out.println(a.sayHello(”John”));Which two are true? (Choose two.)
Image of page 30
Image of page 31
Image of page 32

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture