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?()
第1题:
10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14. } And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine?()
第2题:
1. public class GoTest { 2. public static void main(String[] args) { 3. Sente a = new Sente(); a.go(); 4. Goban b = new Goban(); b.go(); 5. Stone c = new Stone(); c.go(); 6. } 7. } 8. 9. class Sente implements Go { 10. public void go() { System.out.println(”go in Sente.”); } 11. } 12. 13. class Goban extends Sente { 14. public void go() { System.out.println(”go in Goban”); } 15. } 16. 17. class Stone extends Goban implements Go { } 18. 19. interface Go { public void go(); } What is the result?()
第3题:
Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?() class A {} class B extends A {} class C extends A {} public class Q3ae4 { public static void main(String args[]) { A x = new A(); B y = new B(); C z = new C(); // insert statement here } }
第4题:
public class X { public X aMethod() { return this;} } public class Y extends X { } Which two methods can be added to the definition of class Y?()
第5题:
现有: interface Data {public void load();} abstract class Info {public abstract void load();} 下列类定义中正确使用Data和Info的是哪项?()
第6题:
10. interface Foo {} 11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args) { 15. Beta x = new Beta(); 16. // insert code here 17. } 18. } Which code, inserted at line 16, will cause a java.lang.ClassCastException?()
第7题:
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?()
第8题:
Alpha a = x;
Foo f= (Delta)x;
Foo f= (Alpha)x;
Beta b = (Beta)(Alpha)x;
第9题:
StackOverflowError
NullPointerException
NumberFormatException
IllegalArgumentException
ExceptionlnlnitializerError
第10题:
Cat is-a Animal
Cat is-a Jumper
Dog is-a Animal
Dog is-a Jumper
Cat has-a Animal
Beagle has-a Tail
Beagle has-a Jumper
第11题:
add this code after line 11: list = (List
change lines 12 and 13 to: list.add
change the method signature on line 11 to: public void addStrings(List< extends String> list) {
change the method signature on line 11 to: public void addStrings(List< super String> list) {
No changes are necessary. This method compiles without warnings.
第12题:
x = y;
z = x;
y = (B) x;
z = (C) y;
y = (A) y;
第13题:
11. public void addStrings(List list) { 12. list.add(”foo”); 13. list.add(”bar”); 14. } What must you change in this method to compile without warnings?()
第14题:
interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?()
第15题:
public class A extends Thread { A() { setDaemon(true); } public void run() { (new B()).start(); try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“A done”); } class B extends Thread { public void run() { try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“B done”); } } public static void main(String[] args) { (new A()).start(); } } What is the result?()
第16题:
现有: interface Animal { void eat () ; } //insert code here public class HouseCat extends Feline { public void eat() { } } 和五个申明 abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat () ; } abstract class Feline implements Animal { public void eat();} abstract class Feline implements Animal { public void eat() {} } abstract class Feline implements Animal { abstract public void eat();} 结果为:()
第17题:
10. class Inner { 11. private int x; 12. public void setX( int x) { this.x = x; } 13. public int getX() { return x; } 14. } 15. 16. class Outer { 17. private Inner y; 18. public void setY( Inner y) { this.y = y; } 19. public Inner getY() { return y; } 20. } 21. 22. public class Gamma { 23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner(); 26.int n=10; 27. i.setX(n); 28. o.setY(i); 29. // insert code here 30. System.out.println( o.getY().getX()); 31. } 32. } Which three code fragments, added individually at line 29, produce the output 100?()
第18题:
public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly?()
第19题:
n = 100;
i.setX( 100);
o.getY().setX( 100);
i = new Inner(); i.setX( 100);
o.setY( i); i = new Inner(); i.setX( 100);
i = new Inner(); i.setX( 100); o.setY( i);
第20题:
public void aMethod() {}
private void aMethod() {}
public void aMethod(String s) {}
private Y aMethod() { return null; }
public X aMethod() { return new Y(); }
第21题:
public class Circle implements Shape { private int radius; }
public abstract class Circle extends Shape { private int radius; }
public class Circle extends Shape { private int radius; public void draw(); }
public abstract class Circle implements Shape { private int radius; public void draw(); }
public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
第22题:
public class Employee extends Info implements Data { public void load() { /*do something*/ } }
public class Employee implements Info extends Data { public void load() { /*do something*/ } }
public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }
public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }
public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }
public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
第23题:
public class Employee implements Info extends Data { public void load(){/*dosomething*/} }
public class Employee extends Inf.implements Data{ public void load() {/*do something*/} }
public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/} public void load(){/*do something*/} }
public class Employee extends Inf implements Data { public void Data.1oad() {/*do something*/) public void info.1oad(){/*do something*/} }