多项选择题

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(); }


您可能感兴趣的试卷

你可能感兴趣的试题

1.单项选择题

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.

2.单项选择题

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.

3.单项选择题

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.

8.单项选择题

package geometry; 
public class Hypotenuse { 
public InnerTriangle it = new InnerTriangle(); 
class InnerTriangle { 
public int base; 
public int height; 
} 
} 
Which is true about the class of an object that can reference the variable base? ()

A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.

9.单项选择题

1. public class Target { 
2. private int i = 0; 
3. public int addOne() { 
4. return ++i; 
5. } 
6. } 
And: 
1. public class Client { 
2. public static void main(String[] args) { 
3. System.out.println(new Target().addOne()); 
4. } 
5. } 
Which change can you make to Target without affecting Client?() 

A. Line 4 of class Target can be changed to return i++;
B. Line 2 of class Target can be changed to private int i = 1;
C. Line 3 of class Target can be changed to private int addOne() {
D. Line 2 of class Target can be changed to private Integer i = 0;

10.单项选择题

package test; 
class Target { 
public String name = “hello”; 
} 
What can directly access and change the value of the variable name?() 

A. any class
B. only the Target class
C. any class in the test package
D. any class that extends Target