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. 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.
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.
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.
abstract class A {
abstract void al();
void a2() { }
}
class B extends A {
void a1() { }
void a2() { }
}
class C extends B { void c1() { } }
and:
A x = new B(); C y = new C(); A z = new C();
Which four are valid examples of polymorphic method calls?()
A. x.a2();
B. z.a2();
C. z.c1();
D. z.a1();
E. y.c1();
F. x.a1();
11. abstract class Vehicle { public int speed() { return 0; } }
12. class Car extends Vehicle { public int speed() { return 60; } }
13. class RaceCar extends Car { public int speed() { return 150; }}
......
21. RaceCar racer = new RaceCar();
22. Car car = new RaceCar();
23. Vehicle vehicle = new RaceCar();
24. System.out.println(racer.speed() + “, „ + car.speed()
25. + “, “+ vehicle.speed());
What is the result?()
A. 0, 0,0
B. 150, 60, 0
C. Compilation fails.
D. 150, 150, 150
E. An exception is thrown at runtime.
11. class Animal { public String noise() { return “peep”; } }
12. class Dog extends Animal {
13. public String noise() { return “bark”; }
14. }
15. class Cat extends Animal {
16. public String noise() { return “meow”; }
17. }
.....
30. Animal animal = new Dog();
31. Cat cat = (Cat)animal;
32. System.out.printIn(cat.noise());
What is the result?()
A. peep
B. bark
C. meow
D. Compilation fails.
E. An exception is thrown at runtime.
class ClassA {}
class ClassB extends ClassA {}
class ClassC extends ClassA {}
and:
ClassA p0 = new ClassA();
ClassB p1 = new ClassB();
ClassC p2 = new ClassC();
ClassA p3 = new ClassB();
ClassA p4 = new ClassC();
Which three are valid?()
A. p0 = p1;
B. p1 =p2;
C. p2 = p4;
D. p2 = (ClassC)p1;
E. p1 = (ClassB)p3;
F. p2 = (ClassC)p4;
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.
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;
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
最新试题
What is the result?()
Which two are possible results?()
What is the result?()
What is the result?()
What is the result?()
Which statement is true?()
What is the result?()
Which statement is true?()
What can be a result?()
Given that Triangle implements Runnable, and:Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute?()