以下是我做SCJP的几道模拟题及答案,但我还有些不懂的地方想请教

shielf 2002-12-21 11:45:04
以下是我做SCJP的几道模拟题及答案,但我还有些不懂的地方想请教各位。
同时也希望能对其他正在准备SCJP的各位战友们有点帮助。
1.Given the following class definition:
class A{
protected int i;
A(int i){
this.i=i;
}
}
which of the following would be a valid inner class for this class?
Select all valid answers:
A. class B{
}
B. class B extends A{
}
C. class B extends A{
B(){System.out.println(“i=”+i);}
}
D. class B{
class A{}
}
E. class A{}

答案是A
另附的说明为: 此题考查内部类及关键字“super”的用法。内部类不能与外部类同名。另外,当B继承A时,A中的构造函数(construct)是带参数的,B中缺省构造函数的函数体为空;而JAVA编译器会为空构造函数体自动添加语句“super();”调用父类构造函数,更进一步是调用父类的参数为空的构造函数。而父类中没有参数为空的构造函数。
那么C为什么不对?C的construct不为空啊?


2.Give the following java source fragement:
//point x
public class Interesting{
//do something
}
Which statement is correctly Java syntax at point x?
A. import java.awt.*;
B.package mypackage
C. static int PI=3.14
D. public class MyClass{//do other thing…}
E. class MyClass{//do something…}
答案是A、E
说明为: X处可以是一个输入,包的定义,类的定义。由于常量或变量的声明只能在类中或方法中,故不能选择C;由于在一个文件中只能有一个public类,故不能选择D。
这样的话B答案应该是正确的,难道是标准答案错了?

3.Float s=new Float(0.9F);
Float t=new Float(0.9F);
Double u=new Double(0.9);
Which expression’s result is true?
A. s==t B. s.equals(t) C. s==u D. t.equals(u)
答案是A、B
说明为: 考察“==”及方法“equals()”的用法。注意以下几点区别:
1)引用类型比较引用;基本类型比较值。
2)equals()方法只能比较引用类型,“==”可比较引用及基本类型。
3)当用equals()方法进行比较时,对类File、String、Date及封装类(Wrapper Class)来说,是比较类型及内容。
4)用“==”进行比较时,符号两边的数据类型必须一致(可相互转换的基本类型除外),否则编译出错。

而我认为A答案应该是错的,使用Wrapper Class就相当于使用一个普通的类而不是基本类型,那么s和t都使用new来创建一个新的类,他们所指向的地址就应该不同才对。


4. Which statement are true about writing a class that is to handle the events issued by a user interface component.
A. Subclassing an adapter is inappropriate in this case.
B. The class should implement some listener interface
C. A class can implement multiple listener interfaces if desired.
D. A subclass of an AWT component cannot listen to its own events.
E. When implements listener interface, a class need only provide those handler methods that it chooses.
答案是B、C
说明为: 此题考察考生对事件处理的理解。D选项是错的,因为控件可以监听自己的事件。另外,当实现一个接口时,必须实现它内部的所有的方法,所以E选项也是错的。

我想问的是A为什么不对?


5.Which contains objects without ordering, duplication, or any particular lookup/retrieval mechanism?
A. Map B. Set C. List D. Collection E. Enumeration
答案是B
这道题只是道概念题,但是我不明白的是题目的意思,到底是说无序可重复还是无序不可重复?(without ordering, duplication, or any particular lookup/retrieval mechanism)


6.What might form part of a correct inner class declaration or combined declaration and instantiation?
A. private class C
B. new SimpleInterface(){
C. new ComplexInterface(x){
D. private final abstract class(
E. new ComplexClass() implements SimpleInterface
答案是AB,可否解释一下?
...全文
28 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyuan_buaa 2002-12-23
  • 打赏
  • 举报
回复
第二题的B的答案少一个分号。
ilka 2002-12-22
  • 打赏
  • 举报
回复
A对!
class A{
protected int i;
A(int i){
this.i=i;
}
class B{
}
}
B是A的内部类(inner class)
shielf 2002-12-22
  • 打赏
  • 举报
回复
还有下面的几道呢?
boman1980 2002-12-22
  • 打赏
  • 举报
回复
第一题的意思是说:如果BASE CLASS的构造函数是带参数的话,DEVISED CLASS
fosdick_j 2002-12-21
  • 打赏
  • 举报
回复
which of the following would be a valid inner class for this class?
Select all valid answers:
搞错了,第一题应该只考inner class 没有涉及到super()的应用阿。
fosdick_j 2002-12-21
  • 打赏
  • 举报
回复
第一题我怎么觉得没一个是对的,第二题的B没有分号
shielf 2002-12-21
  • 打赏
  • 举报
回复
他是没有讲super(),但是因为不加空construct的话,系统自通添加super()

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧