class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?()
A、 TestA
B、 TestB
C、 Compilation fails.
D、 An exception is thrown at runtime.
相关问题推荐
-
class super { public float getNum() {return 3.0f;} } public class Sub extends Super { } Which method, placed at line 6, will cause a compiler error?()
A、 Public float getNum() {return 4.0f; }
B、 Public void getNum (){}
C、 Public void getNum (double d){}
D、 Public double getNum (float d) {retrun 4.0f; }
-
Which will declare a method that forces a subclass to implement it? ()
A、 Public double methoda();
B、 Static void methoda (double d1) {}
C、 Public native double methoda();
D、 Abstract public void methoda();
E、 Protected void methoda (double d1){}
-
1. package foo; 2. 3. import java.util.Vector; 4. 5. private class MyVector extends Vector { 6. int i = 1; 7. public MyVector() { 8. i = 2; 9. } 10. } 11. 12. public class MyNewVector extends MyVector { 13. public MyNewVector () { 14. i = 4; 15. } 16. public static void main (String args []) { 17. MyVector v = new MyNewVector(); 18. } 19. } The file MyNewVector.java is shown in the exhibit. What is the result?()
A、 Compilation will succeed.
B、 Compilation will fail at line 5.
C、 Compilation will fail at line 6.
D、 Compilation will fail at line 14.
E、 Compilation will fail at line 17.
-
class A { public byte getNumber() { return 1; } } class B extends A { public short getNumber() { return 2; } public static void main(String args[]) { B b = new B(); System.out.println(b.getNumber()); } } What is the result?()
A、 1
B、 2
C、 An exception is thrown at runtime.
D、 Compilation fails because of an error in line 8.
E、 Compilation fails because of an error in line 14.
-
public class Team extends java.util.LinkedList { public void addPlayer(Player p) { add(p); } public void compete(Team opponent) { /* more code here */ } } class Player { /* more code here */ } Which two are true?()
AThis code will compile.
BThis code demonstrates proper design of an is-a relationship.
CThis code demonstrates proper design of a has-a relationship.
DA Java programmer using the Team class could remove Player objects from a Team object.