SCJP真题库更新7

QUESTION 25

Exhibit:

What is the result?

A. Value is : 8

B. Compilation fails.

C. Value is : 12

D. Value is ; -12

E. The code runs with no output

F. An exception is thrown at runtime.

 

 

Answer: ( A )

2,value默认是=0;9行实例化一个MultiCale对象,并传了一个参数multiplier=2,10行调用3行的方法;方法内的calculate()又调用2,结果value=0-3;然后super.calculate()调用父类的calculate(),value=-3+7=4;然后6,value=value*multiplier=4*2=8;然后到11,输出value is : 8

参考大纲:面向对象

 

QUESTION 26

Given the exhibit:

 

Which statement is true? 

A. The class is fully encapsulated

B. The code demonstrates polymorphism.

C. The ownerName variable breaks encapsulation

D. The CardID and limit variables break polymorphism

E. The setCardInformation method breaks encapsulation

 

 

Answer: ( C )

24行破坏了封装,应该成private String ownerName;

参考大纲:面向对象 封装

 

QUESTION 27/

Given the exhibit:

What is the result?

A. peep

B. bark

C. move

D. Compilation fails.

E. An exception is thrown at runtime

 

 

Answer: ( E )

31行运行时发生造型异常,运行时错误!!30行后Animal的实体是dog,31行有转型到cat是不对的(兄弟类之间不能转换)!编译是没有错误是因为dog cat有共同的父类,

参考大纲:面向对象 多态

 

QUESTION 28------------概念

Exhibit:

 

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;

 

 

Answer: ( DE )

D 父类无默认构造函数,子类需显示调用父类的构造函数 利用super(参数)来调用父类的构造函数

E wheelCount为私有变量,子类无法访问,改成default,public protected都可以,本题改成protected比较合适

2行改为 protected int wheelCount;

And 2行和3行之间插入super(vin);

参考大纲:面向对象

 

QUESTION 29------------多态

Given the exhibit:

 

polymorphism? (choose three)

A. public void add (C c) { c.getValue ( ); }

B. public void add (B b) { b.getValue ( ); }

C. public void add (A a) { a.getValue ( ); }

D. public void add (A a, B b) { a.getValue ( ); }

E. public void add (C c1, C c2) { c1.getValue ( ); }

 

 

Answer: ( B, C, D )

A E 只是简单的使用C的方法

多态必须存在继承

参考大纲:面向对象 多态

 

QUESTION 30

Given the exhibit:

 

Which statement should be placed at line 14 to suggest that the virtual machine

expend effort toward recycling the memory used by the object Certkiller ? 

A. System.gc ( )

B. Runtime. Gc ( )

C. System.freeMemory ( )

D. Runtime.getRuntime ( ) .growHeap ( )

E. Runtime.getRuntime ( ) .freeMemory ( )

 

 

Answer: ( A )

建议JVM进行资源回收的方法:

System.gc();

Runtime.getRuntime().gc();

参考大纲:面向对象 垃圾回收机制

本文由:水晶手链 整理

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