单项选择题

1. public class SimpleCalc { 
2. public int value; 
3. public void calculate() { value += 7; } 
4. }
And: 
1. public class MultiCalc extends SimpleCalc { 
2. public void calculate() { value -= 3; } 
3. public void calculate(int multiplier) { 
4. calculate(); 
5. super.calculate(); 
6. value *=multiplier; 
7. } 
8. public static void main(String[] args) { 
9. MultiCalc calculator = new MultiCalc(); 
10. calculator.calculate(2); 
11. System.out.println(”Value is: “+ calculator.value); 
12. } 
13. } 
What is the result?() 

A. Value is: 8
B. Compilation fails.
C. Value is: 12
D. Value is: -12
E. The code runs with no output.
F. An exception is thrown at runtime.


您可能感兴趣的试卷

你可能感兴趣的试题

1.多项选择题

1. class Super { 
2. private int a; 
3. protected Super(int a) { this.a = a; } 
4. }
 ..... 
11. class Sub extends Super { 
12. public Sub(int a) { super(a); } 
13. public Sub() { this.a= 5; } 
14. } 
Which two, independently, will allow Sub to compile?()

A. Change line 2 to: public int a;
B. Change line 2 to: protected int a;
C. Change line 13 to: public Sub() { this(5); }
D. Change line 13 to: public Sub() { super(5); }
E. Change line 13 to: public Sub() { super(a); }

5.多项选择题

interface A { public int getValue() } 
class B implements A { 
public int getValue() { return 1; } 
} 
class C extends B { 
// insert code here 
} 
Which three code fragments, inserted individually at line 15, make use of polymorphism?()

A. public void add(C c) { c.getValue(); }
B. public void add(B b) { b.getValue(); }
C. public void add(A a) { a.getValue(); }
D. public void add(A a, B b) { a.getValue(); }
E. public void add(C c1, C c2) { c1.getValue(); }

6.单项选择题

1. interface A { public void aMethod(); } 
2. interface B { public void bMethod(); } 
3. interface C extends A,B { public void cMethod(); } 
4. class D implements B { 
5. public void bMethod() { } 
6. } 
7. class E extends D implements C { 
8. public void aMethod() { } 
9. public void bMethod() { } 
10. public void cMethod() { } 
11. } 
What is the result?() 

A. Compilation fails because of an error in line 3.
B. Compilation fails because of an error in line 7.
C. Compilation fails because of an error in line 9.
D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod()defined in Line 5.
E. If you define D e = (D)(new E()),then e.bMethod() invokes the version of bMethod() defined in Line 5.
F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

7.单项选择题

1. class SuperClass { 
2. public a geta() { 
3. return new a(); 
4. } 
5. } 
6. class SubClass extends SuperClass { 
7. public b geta() { 
8. return new b(); 
9. } 
10. } 
Which is true?() 

A. Compilation will succeed if a extends b.
B. Compilation will succeed if b extends a.
C. Compilation will always fail because of an error in line 7.
D. Compilation will always fail because of an error in line 8.

8.单项选择题

10. interface A { void x(); } 
11. class B implements A { public void x() { } public voidy() { } } 
12. class C extends B { public void x() {} } 
And: 
20. java.util.List list = new java.util.ArrayList(); 
21. list.add(new B()); 
22. list.add(new C()); 
23. for (A a:list) { 
24. a.x(); 
25. a.y();; 
26. } 
What is the result?() 
 

A. The code runs with no output.
B. An exception is thrown at runtime.
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 21.
E. Compilation fails because of an error in line 23.
F. Compilation fails because of an error in line 25.