当前位置:首页 > SCJP题库 Module3 - 图文
10. abstract class A { 11. abstract void al(); 12. void a2() { } 13. }
14. class B extends A { 15. void a1() { } 16. void a2() { } 17. }
18. class C extends B { void c1() { } } and:
A x = new B(); C y = new C(); A z = new C();
Which four are valid examples of polymorphic method calls? (Choose four.)
A. x.a2(); B. z.a2(); C. z.c1(); D. z.a1(); E. y.c1(); F. x.a1();
Answer: ABDF 自己做的
Question 21
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(\11. } 12.
13. class Goban extends Sente {
14. public void go() { System.out.println(\15. } 16.
17. class Stone extends Goban implements Go { } 这句恶心,在实现一次go接口,也可以,不要被忽悠了 18.
19. interface Go { public void go(); } What is the result? A. go in Goban
go in Sente go in Sente B. go in Sente
go in Sente go in Goban C. go in Sente
go in Goban go in Goban D. go in Goban
go in Goban
9
go in Sente
E. Compilation fails because of an error in line 17. Answer: C
Question 22 Given:
1. class ClassA {
2. public int numberOfinstances;
3. protected ClassA(int numberOfinstances) { 4. this.numberOflnstances = numberOfinstances; 5. } 6. }
7. public class ExtendedA extends ClassA { 8. private ExtendedA(int numberOfInstances) { 9. super(numberOfiInstances); 10. }
11. public static void main(String[] args) { 12. ExtendedA ext = new ExtendedA(420);
13. System.out.print(ext.numberOfInstances); 14. } 15. }
Which is true?
A. 420 is the output.
B. An exception is thrown at runtime.
C. All constructors must be declared public.
D. Constructors CANNOT use the private modifier. E. Constructors CANNOT use the protected modifier. Answer: A 无争议
Question 23 Given:
1. class Super { 2. private int a;
3. protected Super(int a) { this.a = a; } 4. } .....
11. class Sub extends Super {
12. public Sub(int a) { super(a); } 13. public Sub() { this.a= 5; } 14. }
Which two, independently, will allow Sub to compile? (Choose two.) A. Change line 2 to:
public int a;
B. Change line 2 to:
protected int a; C. Change line 13 to:
public Sub() { this(5); } D. Change line 13 to:
public Sub() { super(5); } E. Change line 13 to:
public Sub() { super(a); } Answer: CD 考点:构造方法的调用
Question 24
10
Given:
10. public class Hello { 11. String title; 12. int value;
13. public Hello() { 14. title += \15. }
16. public Hello(int value) { 17. this.value = value; 18. title = \
19. Hello(); 调用自己的构造方法要用this 20. } 21. } and:
30. Hello c = new Hello(5);
31. System.out.println(c.title); What is the result? A. Hello
B. Hello World
C. Compilation fails. D. Hello World 5
E. The code runs with no output.
F. An exception is thrown at runtime. Answer: C 骂了隔壁,jb题
Question 25
1. public class Car {
2. private int wheelCount; 3. private String vin;
4. public Car(String vin) { 5. this.vin = vin;
6. this.wheelCount = 4; 7. }
8. public String drive() { 9. return \10. }
11. public String getInfo() {
12. return \13. } 14. } And:
1. public class MeGo extends Car { 2. public MeGo(String vin) { 3. this.wheelCount = 3; 4. } 5. }
What two must the programmer do to correct the compilation errors? (Choose two.)
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 父类
11
wheelCount为private,肯定不能修改值,权限改为protected
F. change line 3 in the MeGo class to super.wheelCount = 3; Answer: DE
Question 26
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 5, 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); Answer: D 无争议
Question 27
Which Man class properly(适当) represents(表示) the relationship 关系“Man has a best friend who is a Dog”? A. class Man extends Dog { } B. class Man implements Dog { }
C. class Man { private BestFriend dog; } D. class Man { private Dog bestFriend; } E. class Man { private Dog
Question 28
Which four are true? (Choose four.)
A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance. C. Has-a relationships can be implemented using instance variables. D. Is-a relationships can be implemented using the extends keyword. E. Is-a relationships can be implemented using the implements keyword. F. The relationship between Movie and Actress is an example of an is-a
12
共分享92篇相关文档