SCJP真题库更新10

QUESTION 41

Given the exhibit:

 

What is the result when this code executed? 

A. 1

B. 3

C. 123

D. 321

E. The code runs with no output

 

 

Answer: ( C )

子类先调用父类的构造函数,在调用自己的构造函数;

参考大纲:Java语言基础 —继承和构造函数

 

QUESTION 42

Place the code fragments in position to complete the Displayable interface.

Answer: (  )

interface  Displayable   extends  Reloadable{

        public void display();

}

参考大纲:面向对象 接口继承

 

QUESTION 43

Given the exhibit:

 

Which code, inserted at line 14, allows the Sprite class to compile? 

A. Direction d = NORTH

B. Certkiller .Direction d = NORTH

C. Direction d = Direction.NORTH

D. Certkiller .Direction d = Certkiller .Direction. NORTH

 

 

Answer: ( D )

enum枚举关键字

一个enum就像一个class因此参照内部类的使用方法选择D

参考大纲:面向对象 enum类型

 

QUESTION 44

Exhibit:

Which three statements are true? (Choose three) 

A. Compilation fails

B. The code compiles and the output is 2

C. If lines 16, 17 and 18 were removed, compilation would fail.

D. If lines 24,25, and 26 were removed, compilation would fail.

E. If lines 16,17 and 18 were removed, the code would compile and the output would be 2.

F. If line 24,25 and 26 were removed, the code would compile and the output would be 1.

 

 

Answer: ( BEF )

一个内部类Class A,一个方法内部类Class A

参考大纲:面向对象

 

QUESTION 45

Add methods to the Beta class to make it compile correctly.

Answer: (  )

 

public class Beata extends Alpha{

public void bar(int x){}

public int bar(String x){return 1;}

public void bar(int x, int y){}

}

private void bar(int x){} 错误 覆写时存取权限不可以小于原方法

public void bar(int x){} 正确 覆写

public int bar(String x){return l;} 正确 覆载

public Alpha bar(int x){int x}{}  错误 覆写时的传回值可以与原来的方法返回值相等或者是子类别,本例中原来的返回是void,这样子类别中只能用void来修饰bar()方法。

public void bar(int x, int y){} 正确 覆载

public int bar(int x){return x;} 错误 覆载

参考大纲:面向对象 覆写和覆载

你可能感兴趣的:(scjp,真题)