您的位置:
首页 >> 资讯资料 >> IT培训 >> 正文:SUN认证Java2程序员考试(SCJP) 试题解析(2)

SUN认证Java2程序员考试(SCJP) 试题解析(2)

Which of the following lines of code will compile without error?   
A.   
int i=0;   
if (i) {   
System.out.println(“Hi”);   
}   
B.   
boolean b=true;   
boolean b2=true;   
if(b==b2) {   
System.out.println(“So true”);   
}   
C.   
int i=1;   
int j=2;   
if(i==1|| j==2)   
System.out.println(“OK”);   
D.   
int i=1;   
int j=2;   
if (i==1 &| j==2)   
System.out.println(“OK”);   
解答:B, C   
点评:选项A错,因为if语句后需要一个boolean类型的表达式。逻辑操作有^、&、| 和 &&、||,但是“&|”是非法的,所以选项D不正确。   

例题5:   
Which two demonstrate a "has a" relationship? (Choose two)   
A. public interface Person { }   
public class Employee extends Person{ }   
B. public interface Shape { }   
public interface Rectandle extends Shape { }   
C. public interface Colorable { }   
public class Shape implements Colorable   
{ }   
D. public class Species{ }   
public class Animal{private Species species;}   
E. interface Component{ }   
class Container implements Component{   
private Component[] children;   
}   
解答:D, E   

  点评: 在Java中代码重用有两种可能的方式,即组合(“has a”关系)和继承(“is a”关系)。“has a”关系是通过定义类的属性的方式实现的;而“is a”关系是通过类继承实现的。本例中选项A、B、C体现了“is a”关系;选项D、E体现了“has a”关系。   

例题6:   
Which two statements are true for the class java.util.TreeSet? (Choose two)   
A. The elements in the collection are ordered.   
B. The collection is guaranteed to be immutable.   
C. The elements in the collection are guaranteed to be unique.   
D. The elements in the collection are accessed using a unique key.   

E. The elements in the collection are guaranteed to be synchronized   
解答:A, C   
  点评:TreeSet类实现了Set接口。Set的特点是其中的元素惟一,选项C正确。由于采用了树形存储方式,将元素有序地组织起来,所以选项A也正确。   

例题7:   
True or False: Readers have methods that can read and return floats and doubles.   
A. Ture   
B. False   
解答:B   
  点评: Reader/Writer只处理Unicode字符的输入输出。float和double可以通过stream进行I/O.   

例题8:   
What does the following paint() method draw?   
1. public void paint(Graphics g) {   
2. g.drawString(“Any question”, 10, 0);   
3. }   
A. The string “Any question?”, with its top-left corner at 10,0   
B. A little squiggle coming down from the top of the 
;component.   
解答:B   
  点评:drawString(String str, int x, int y)方法是使用当前的颜色和字符,将str的内容显示出来,并且最左的字符的基线从(x,y)开始。在本题中,y=0,所以基线位于最顶端。我们只能看到下行字母的一部分,即字母‘y’、‘q’的下半部分。
【作者:本站编辑┊来源:学习联盟┊2005-01-29】TAGS:
评论与咨询 内容报错
姓名: 电话: 邮箱: 地址:

  • ·本咨询平台是部分培训机构与本站指定的网上报名、咨询的专用平台,您可以通过此处提交您的信息,我们或该机构会根据您所提交的信息及时给予回复;
  • ·为了更好的问您服务,请填写您真实的姓名和相关联系方式,以便我们能及时给您答复;
  • ·不得提交有关违反国家互联网规定的不良信息,对于违规者我们有权追究你的法律责任!若有任何问题请 联系我们
关于我们 | 服务条款 | 广告服务 | 客服中心 | 网站导航 - 设为首页 - 收藏本站
Copyright © 2006-2008 www.0512edu.com.cn All Rights Reserved
苏州培训资讯网 版权所有
Powered By:AspArticle2.0 在远方