public void m1() { }
protected void m1() { }
private void m1() { }
void m2() { }
public void m2() { }
protected void m2() { }
第1题:
public class ExceptionTest { class TestException extends Exception {} public void runTest () throws TestException {} public void test () /* Point X*/ { runTest (); } } At point X on line 4, which code can be added to make the code compile?()
第2题:
1. class Alpha { void m1() {} } 2. class Beta extends Alpha { void m2() { } } 3. class Gamma extends Beta { } 4. 5. class GreekTest { 6. public static void main(String [] args) { 7. a Alpha [] a = {new Alpha(), new Beta(), new Gamma() }; 8. for(Alpha a2 : a) { 9. a2.m1(); 10. if (a2 instanceof Beta || a2 instanceof Gamma) 11. //insert code here 12. } 13. } 14. } 哪一行代码插入到第11行,将编译但是会在运行时产生异常?()
第3题:
Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object. class Base { public void print( ) { System.out.println("base"); } } class Extention extends Base { public void print( ) { System.out.println("extension"); // insert line of implementation here } } public class Q294d { public static void main(String args[]) { Extention ext = new Extention( ); ext.print( ); } } Fill in a single line of implementation.()
第4题:
Consider the following class: class Test(int i) { void test(int i) { System.out.println(“I am an int.”); } void test(String s) { System.out.println(“I am a string.”); } public static void main(String args) { Test t=new Test(); char ch=“y”; t.test(ch); } } Which of the statements below is true?()
第5题:
Given: 10. class One { 11. void foo() { } 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two?()
第6题:
public void main(String args[])
public void static main(String args[])
public static main(String[] argv)
final public static void main(String [] array)
public static void main(String args[])
第7题:
new Thread() { public void run() { doStuff(); } }
new Thread() { public void start() { doStuff(); } }
new Thread() { public void start() { doStuff(); } } .run();
new Thread() { public void run() { doStuff(); } } .start();
new Thread(new Runnable() { public void run() { doStuff(); } } ).run();
new Thread(new Runnable() { public void run() { doStuff(); } }).start();
第8题:
public void finalize()
protected int finalize()
C.protected void finalize(int
protected void finalize()throws Throwable
第9题:
new Thread() {public void run() { doStuff(); }};
new Thread() {public void start() { doStuff(); }};
new Thread() {public void start() { doStuff(); }}.run();
new Thread() {public void run() { doStuff(); }}.start();
new Thread(new Runnable() {public void run() { doStuff(); }}).start();
第10题:
a2.m2();
((Beta)a2).m2();
((Alpha)a2).m2();
((Gamma)a2).m2();
第11题:
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 */ } }
第12题:
Void setVar(float f) {x = f;}
Public void setVar(int f) {x = f;}
Public void setVar(float f) {x = f;}
Public double setVar(float f) {x = f;}
Public final void setVar(float f) {x = f;}
Protected float setVar() {x=3.0f; return 3.0f; }
第13题:
Which two code fragments will execute the method doStuff() in a separate thread?()
第14题:
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?()
第15题:
Which three will compile and run without exception?()
第16题:
Which two code fragments will execute the method doStuff() in a separate thread?()
第17题:
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
int foo() { /* more code here */ }
void foo() { /* more code here */ }
第18题:
int foo() { /* more code here */ }
void foo() { /* more code here */ }
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
第19题:
protected int blipvert(long x) { return 0; }
protected long blipvert(int x) { return 0; }
private int blipvert(long x) { return 0; }
private int blipvert(int x) { return 0; }
public int blipvert(int x) { return 0; }
protected long blipvert(long x) { return 0; }
protected long blipvert(int x, int y) { return 0; }
第20题:
public void add(C c) { c.getValue(); }
public void add(B b) { b.getValue(); }
public void add(A a) { a.getValue(); }
public void add(A a, B b) { a.getValue(); }
public void add(C c1, C c2) { c1.getValue(); }
第21题:
public void aMethod() {}
private void aMethod() {}
public void aMethod(String s) {}
private Y aMethod() { return null; }
public X aMethod() { return new Y(); }
第22题:
int foo() { /* more code here */ }
void foo() { /* more code here */ }
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
第23题:
public void valueUnbound(HttpSessionEvent ev){...}
public void sessionPassivated(HttpSessionEvent ev){...}
public void sessionDidActivate(HttpSessionEvent ev){...}
public void sessionWillPassivate(HttpSessionEvent ev){...}