public class X {
public static void main(String [] args) {
try {
badMethod();
System.out.print(“A”);
}
catch (RuntimeException ex) {
System.out.print(“B”);
}
catch (Exception ex1) {
System.out.print(“C”);
}
finally {
System.out.print(“D”);
}
System.out.print(“E”);
}
public static void badMethod() {
throw new RuntimeException();
}
}
What is the result?()
A. BD
B. BCD
C. BDE
D. BCDE
E. ABCDE
F. Compilation fails.
您可能感兴趣的试卷
你可能感兴趣的试题
switch(x) {
default:
System.out.println(“Hello”);
}
Which two are acceptable types for x?()
A. byte
B. long
C. char
D. float
E. Short
F. Long
A. public
B. private
C. protected
D. transient
E. default access
public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): “assertion failed”;
System.out.println(“finished”);
}
}
What is the result?()
A. finished
B. Compilation fails.
C. An AssertionError is thrown.
D. An AssertionError is thrown and finished is output.
A. 4,4
B. 4,5
C. 5,4
D. 5,5
E. Compilation fails.
public void test(int x) {
int odd = x%2;
if (odd) {
System.out.println(“odd);
} else {
System.out.println(“even”);
}
}
Which statement is true?()
A.Compilation fails.
B. “odd” will always be output.
C. “even” will always be output.
D. “odd” will be output for odd values of x, and “even” for even values.
E. “even” will be output for add values of x, and “odd” for even values.
class Super {
public int getLenght() { return 4; }
}
public class Sub extends Super {
public long getLenght() { return 5; }
public static void main(String[] args) {
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(
sooper.getLenght() + “,” + sub.getLenght() );
}
}
What is the output?()
A. Just after line 13.
B. Just after line 14.
C. Just after line 15.
D. Just after line 16 (that is, as the method returns).
A. The default constructor initializes method variables.
B. The default constructor has the same access as its class.
C. The default constructor invoked the no-arg constructor of the superclass.
D. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
E. The compiler creates a default constructor only when there are no other constructors for the class.
1. class TestA {
2. TestB b;
3. TestA() {
4. b = new TestB(this);
5. }
6. }
7. class TestB {
8. TestA a;
9. TestB(TestA a) {
10. this.a = a;
11. }
12. }
13. class TestAll {
14. public static void main (String args[]) {
15. new TestAll().makeThings();
16. // ...code continues on
17. }
18. void makeThings() {
19. TestA test = new TestA();
20. }
21. }
Which two statements are true after line 15, before main completes?()
A. Line 15 causes a stack overflow.
B. An exception is thrown at runtime.
C. The object referenced by a is eligible for garbage collection.
D. The object referenced by b is eligible for garbage collection.
E. The object referenced by a is not eligible for garbage collection.
F. The object referenced by b is not eligible for garbage collection.
public class X {
public static void main(String [] args) {
try {
badMethod();
System.out.print(“A”);
}
catch (Exception ex) {
System.out.print(“B”);
}
finally {
System.out.print(“C”);
}
System.out.print(“D”);
}
public static void badMethod() {
throw new RuntimeException();
}
}
What is the result? ()
A. AB
B. BC
C. ABC
D. BCD
E. Compilation fails.
A. public class Thing { }
B. public class Thing { public Thing() {} }
C. public class Thing { public Thing(void) {} }
D. public class Thing { public Thing(String s) {} }
E. public class Thing { public void Thing() {} public Thing(String s) {} }
最新试题
Which three will compile and run without exception?()
Which two statements are true?()
What is the appropriate definition of the hashCode method in class Person?()
What is the result?()
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?()
What is the result?()
What can be a result?()
Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5?()
What is the result?()
Which statement is true?()