SUN认证Java2程序员考试(SCJP) 试题解析(2)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SUN认证Java2程序员考试(SCJP) 试题解析(2)SUN认证Java2程序员考试(SCJP) 试题解析(2) which of the following lines of code will pile 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 ponent{ }
class container implements ponent{
private ponent[] 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 aessed 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 ing down from the top of the ;ponent.
解答:b
模板,内容仅供参考