10. public class ClassA {
11. public void methodA() {
12. ClassB classB = new ClassB();
13. classB.getValue();
14. }
15. }
And:
20. class ClassB {
21. public ClassC classC;
22.
23. public String getValue() {
24. return classC.getValue();
25. }
26. }
And:
30. class ClassC {
31. public String value;
32.
33. public String getValue() {
34. value = “ClassB”;
35. return value;
36. }
37. }
Given:
ClassA a = new ClassA();
a.methodA();
What is the result?()
A. Compilation fails.
B. ClassC is displayed.
C. The code runs with no output.
D. An exception is thrown at runtime.
您可能感兴趣的试卷
你可能感兴趣的试题
11. public void someMethod(Object value) {
12. // check for null value ....
20. System.out.println(value.getClass());
21. }
What, inserted at line 12, is the appropriate way to handle a null value?()
A. assert value == null;
B. assert value !null, “value is null”;
C. if (value == null) { throw new AssertionException(”value is null”);
D. if (value == null) { throw new IllegalArgumentException(”value is null”);
static void test() throws RuntimeException {
try {
System.out.print(”test “);
throw new RuntimeException();
}
catch (Exception ex) { System.out.print(”exception “); }
}
public static void main(String[] args) {
try { test(); }
catch (RuntimeException ex) { System.out.print(”runtime “); }
System.out.print(”end “);
}
What is the result?()
A. test end
B. Compilation fails.
C. test runtime end
D. test exception end
E. A Throwable is thrown by main at runtime.
static void test() {
try {
String x=null;
System.out.print(x.toString() +“ “);
}
finally { System.out.print(“finally “); }
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex) { System.out.print(”exception “); }
}
What is the result?()
A. null
B. finally
C. null finally
D. Compilation fails.
E. finally exception
static void test() throws Error {
if (true) throw new AssertionError();
System.out.print(”test “);
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex) { System.out.print(”exception “); }
System.out.print(”elld “);
}
What is the result?()
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.
public static void main(String[] args) {
try {
args=null;
args[0] = “test”;
System.out.println(args[0]);
} catch (Exception ex) {
System.out.println(”Exception”);
} catch (NullPointerException npe) {
System.out.println(”NullPointerException”);
}
}
What is the result?()
A. test
B. Exception
C. Compilation fails.
D. NullPointerException
1. public class a {
2. public void method1() {
3. try {
4. B b=new b();
5. b.method2();
6. // more code here
7. } catch (TestException te) {
8. throw new RuntimeException(te);
9. }
10. }
11. }
1. public class b {
2. public void method2() throws TestException {
3. // more code here
4. }
5. }
1. public class TestException extends Exception {
2. }
Given:
31. public void method() {
32. A a=new a();
33. a.method1();
34. }
Which is true if a TestException is thrown on line 3 of class b?()
A. Line 33 must be called within a try block.
B. The exception thrown by method1 in class a is not required to be caught.
C. The method declared on line 31 must be declared to throw a RuntimeException.
D. On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.
1. public class A {
2. public void method1() {
3. B b=new B();
4. b.method2();
5. // more code here
6. }
7. }
1. public class B {
2. public void method2() {
3.C c=new C();
4. c.method3();
5. // more code here
6. }
7. }
1. public class C {
2. public void method3() {
3. // more code here
4. }
5. }
Given:
25. try {
26. A a=new A();
27. a.method1();
28. } catch (Exception e) {
29. System.out.print(”an error occurred”);
30. }
Which two are true if a NullPointerException is thrown on line 3 of class C?()
A. The application will crash.
B. The code on line 29 will be executed.
C. The code on line 5 of class A will execute.
D. The code on line 5 of class B will execute.
E. The exception will be propagated back to line 27.
84. try {
85. ResourceConnection con = resourceFactory.getConnection();
86. Results r = con.query(”GET INFO FROM CUSTOMER”);
87. info = r.getData();
88. con.close();
89. } catch (ResourceException re) {
90. errorLog.write(re.getMessage());
91. }
92. return info;
Which is true if a ResourceException is thrown on line 86?()
A. Line 92 will not execute.
B. The connection will not be retrieved in line 85.
C. The resource connection will not be closed on line 88.
D. The enclosing method will throw an exception to its caller.
11. static class A {
12. void process() throws Exception { throw new Exception(); }
13. }
14. static class B extends A {
15. void process() { System.out.println(”B”); }
16. }
17. public static void main(String[] args) {
18. new B().process();
19. }
What is the result?()
A. B
B. The code runs with no output.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
11. static classA {
12. void process() throws Exception { throw new Exception(); }
13. }
14. static class B extends A {
15. void process() { System.out.println(”B “); }
16. }
17. public static void main(String[] args) {
18.A a=new B();
19. a.process();
20.}
What is the result?()
A. B
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
F. Compilation fails because of an error in line 19.
最新试题
Which statement is true?()
Which code, inserted at line 4, guarantees that this program will output [1, 2]?()
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true?()
What is the result?()
Which statement is true?()
What is the appropriate definition of the hashCode method in class Person?()
What is the result?()
What is the result?()
What is the result?()
What can be a result?()