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()方法,编译错误

正确

错误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 两个线程依次执行

参考大纲:多线程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值