1. public class SimpleCalc { 2. public int value; 3. public void calculate() { value += 7; } 4. } And: 1. public class MultiCalc extends SimpleCalc { 2. public void calculate() { value -= 3; } 3. public void calculate(int multiplier) { 4. calculate(); 5. super.calculate(); 6. value *=multiplier; 7. } 8. public static void main(String[] args) { 9. MultiCalc calculator = new MultiCalc(); 10. calculator.calculate(2); 11. System.out.println(”Value is: “+ calculator.value); 12. } 13. } What is the result?()
第1题:
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?()
第2题:
1. public class a { 2. public void method1() { 3. try { 4. B b=new b(); 5. b.method2(); 6. // more code here 7. } catch (TestException te) { 8. throw new RuntimeException(te); 9. } 10. } 11. } 1. public class b { 2. public void method2() throws TestException { 3. // more code here 4. } 5. } 1. public class TestException extends Exception { 2. } Given: 31. public void method() { 32. A a=new a(); 33. a.method1(); 34. } Which is true if a TestException is thrown on line 3 of class b?()
第3题:
Which three demonstrate an “is a” relationship?()
第4题:
Which two allow the class Thing to be instantiated using new Thing()?
第5题:
Which two demonstrate an “is a” relationship?()
第6题:
1. public class OuterClass { 2. private double d1 = 1.0; 3. // insert code here 4. } Which two are valid if inserted at line 3?()
第7题:
1. public class enclosingone ( 2. public class insideone{} 3. ) 4. public class inertest( 5. public static void main (string[]args)( 6. enclosingone eo= new enclosingone (); 7. //insert code here 8. ) 9. ) Which statement at line 7 constructs an instance of the inner class?()
第8题:
public class X { } public class Y extends X { }
public interface Shape { } public interface Rectangle extends Shape{ }
public interface Color { } public class Shape { private Color color; }
public interface Species { } public class Animal { private Species species; }
public class Person { } public class Employee { public Employee(Person person) { }
interface Component { } class Container implements Component { private Component[] children; }
第9题:
Compilation of both classes will fail.
Compilation of both classes will succeed.
Compilation of class a will fail. Compilation of class b will succeed.
Compilation of class a will fail. Compilation of class a will succeed.
第10题:
Public float getNum() {return 4.0f; }
Public void getNum () { }
Public void getNum (double d) { }
Public double getNum (float d) {retrun 4.0f; }
第11题:
Line 33 must be called within a try block.
The exception thrown by method1 in class a is not required to be caught.
The method declared on line 31 must be declared to throw a RuntimeException.
On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.
第12题:
The application will crash.
The code on line 29 will be executed.
The code on line 5 of class A will execute.
The code on line 5 of class B will execute.
The exception will be propagated back to line 27.
第13题:
1. public interface A { 2. public void doSomething(String thing); 3. } 1. public class AImpl implements A { 2. public void doSomething(String msg) { } 3. } 1. public class B { 2. public A doit() { 3. // more code here 4. } 5. 6. public String execute() { 7. // more code here 8. } 9. } 1. public class C extends B { 2. public AImpl doit() { 3. // more code here 4. } 5. 6. public Object execute() { 7. // more code here 8. } 9. } Which statement is true about the classes and interfaces in the exhibit?()
第14题:
1. public class A { 2. void A() { 3. System.out.println(“Class A”); 4. } 5. public static void main(String[] args) { 6. new A(); 7. } 8. } What is the result?()
第15题:
interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?()
第16题:
Which the two demonstrate an “is a” relationship?()
第17题:
What produces a compiler error?()
第18题:
1. class super { 2. public float getNum() {return 3.0f;} 3. } 4. 5. public class Sub extends Super { 6. 7. } Which method, placed at line 6, will cause a compiler error?()
第19题:
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*/ } }
第20题:
InsideOnew ei= eo.new InsideOn();
Eo.InsideOne ei = eo.new InsideOne();
InsideOne ei = EnclosingOne.new InsideOne();
EnclosingOne.InsideOne ei = eo.new InsideOne();
第21题:
public class Thing { }
public class Thing { public Thing() {} }
public class Thing { public Thing(void) {} }
public class Thing { public Thing(String s) {} }
public class Thing { public void Thing() {} public Thing(String s) {} }
第22题:
0
1
2
3
第23题:
static class InnerOne { public double methoda() { return d1; } }
static class InnerOne { static double methoda() { return d1; } }
private class InnerOne { public double methoda() { return d1; } }
protected class InnerOne { static double methoda() { return d1; } }
public abstract class InnerOne { public abstract double methoda(); }
第24题:
class A { public A(int x) {} }
class A {} class B extends A { B() {} }
class A { A() {} } class B { public B() {} }
class Z { public Z(int) {} } class A extends Z {}