单项选择题
public class Foo {
public int a;
public Foo() { a = 3; }
public void addFive() { a += 5; }
}
and:
public class Bar extends Foo {
public int a;
public Bar() { a = 8; }
public void addFive() { this.a +=5; }
}
invoked with:
Foo foo = new Bar();
foo.addFive();
System.out.println(”Value: “+ foo.a);
What is the result?()
A. Value: 3
B. Value: 8
C. Value: 13
D. Compilation fails.
E. The code runs with no output.
F. An exception is thrown at runtime.
相关考题
-
多项选择题
1. public class Blip { 2. protected int blipvert(int x) { return 0; } 3. } 4. class Vert extends Blip { 5. // insert code here 6. } Which five methods, inserted independently at line 5, will compile?()
A. public int blipvert(int x) { return 0; }
B. private int blipvert(int x) { return 0; }
C. private int blipvert(long x) { return 0; }
D. protected long blipvert(int x, int y) { return 0; }
E. protected int blipvert(long x) { return 0; }
F. protected long blipvert(long x) { return 0; }
G.protected long blipvert(int x) { return 0; } -
单项选择题
1. public class Employee { 2. String name; 3. double baseSalary; 4. Employee(String name, double baseSalary) { 5. this.name = name; 6. this.baseSalary = baseSalary; 7. } 8. } And: 1. public class Salesperson extends Employee { 2. double commission; 3. public Salesperson(String name, double baseSalary, 4. double commission) { 5. // insert code here 6. } 7. } Which code, inserted at line 7, completes the Salesperson constructor?()
A. this.commission = commission;
B. superb(); commission = commission;
C. this.commission = commission; superb();
D. super(name, baseSalary); this.commission = commission;
E. super(); this.commission = commission;
F. this.commission = commission; super(name, baseSalary); -
多项选择题
public class Car { private int wheelCount; private String vin; public Car(String vin) { this.vin = vin; this.wheelCount = 4; } public String drive() { return “zoom-zoom”; } public String getInfo() { return “VIN: “+ vin + “wheels: “+ wheelCount; } } And: public class MeGo extends Car { public MeGo(String vin) { this.wheelCount = 3; } } What two must the programmer do to correct the compilation errors?()
A. insert a call to this() in the Car constructor
B. insert a call to this() in the MeGo constructor
C. insert a call to super() in the MeGo constructor
D. insert a call to super(vin) in the MeGo constructor
E. change the wheelCount variable in Car to protected
F. change line 3 in the MeGo class to super.wheelCount = 3;
