SCJP真题库更新4

QUESTION 10

Given the exhibit:

What is the result? 

A. short Long

B. SHORT LONG

C. Compilation fails

D. An exception is thrown at runtime

 

 

Answer: ( C )   向上就近原则.

20行的go(z)将会依序找go(int i), go(long l),go(float f), go(double d) go(Integer i)方法.但是并不会自动向上转型Long然后再呼叫go(Long n),这种依顺序向上找的特性只会发生在对应端基本资料型别的情况下,

参考大纲:面向对象 重载; 实用API 自动封包、拆包

 

 

QUESTION 11

Given the exhibit:

* d is valid , non-null Date object

* df is a valid, non-null DateFormat object set to the current local

What outputs the current local's country name and the appropriate version of D's date? 

A. Locale loc = Locale.getLocal ( );

System.out printIn (loc.getDisplayCountry ( )

B. Locale loc = Locale.getDefault ( );

System.out printIn (loc.getDisplayCountry ( ) + " " +df. format (d) );

C. Locale loc = Locale.getLocal ( );

System.out printIn (loc.getDisplayCountry ( ) + " " +df. setDateFormat (d) );

D. Locale loc = Locale.getDefault ( );

System.out printIn (loc.getDisplayCountry ( ) + " " +df.seDateFormat (d) );

 

 

Answer: ( B )

A  Locale类没有getLocal()方法,编译错误

B  正确

C  错误Locale类没有getLocal( )方法  DateFormat没有setDateFormat( )方法,编译错误

D  DateFormat没有setDateFormat( )方法 编译错误

参考大纲:实用API java.util java.text

 

QUESTION 12

Given the exhibit:

What is the result? 

A. Compilation fails.

B. An exception is thrown at runtime

C. The code executes and prints " running"

D. The code executes and prints "runningrunning"

E. The code executes and prints "runningrunningrunning

 

 

Answer: ( E )

t.run()调用main主线程去执行2-4行的run(),就是一次普通的方法调用 ;t.start()表示起用thread线程负责去执行2-4行的run();   2-4行的代码改为:

public void run(){

        String threadName=Thread.currentThread().getName();

System.out.println(threadName+”:running”);

}

这样就可以看出是谁调用了run(),显示如下:

main : running

main : running

Thread-o : running

参考大纲:多线程

 

QUESTION 13------------仔细看看

Exhibit:

Which two are possible results? (choose two) 

A. 0,2,4,4,6,8,10,6,   

B. 0,2,4,6,8,10,2,4,

C. 0,2,4,6,8,10,12,14,   

D. 0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14,

E. 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,

 

 

Answer: ( A, C)

A 第一个线程循环到第三遍使得x等于4,并执行完第8句后挂起(此时current也是4);第二个线程开始执行,执行完以后第一个线程接着执行最后一次循环,打印6

 

C 两个线程依次执行

参考大纲:多线程

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