没有合适的资源?快使用搜索试试~ 我知道了~
看看这些试题,也许对你的认证之路有所帮助!加油! 无论你是个新手,还是程序设计方面的专家,你都会惊异于Sun公司Java的无穷魅力。Java带给你的并不仅仅是面向对象、开放、平台无关、易用、安全和“Write once, run anywhere”等软件开发方面的优势,更重要的一点是,它提供了一种新颖的表达思想的方式,一种全新的思维模式。随着待解决问题的规模不断膨胀,Java彻底的面向对象思想的灵
资源推荐
资源详情
资源评论
无论你是个新手,还是程序设计方面的专家,你都会惊异于 Sun 公司 Java 的无穷魅力。
Java 带给你的并不仅仅是面向对象、开放、平台无关、易用、安全和“Write once, run
anywhere”等软件开发方面的优势,更重要的一点是,它提供了一种新颖的表达思想的方式,
一种全新的思维模式。随着待解决问题的规模不断膨胀,Java 彻底的面向对象思想的灵活性
就会凸现出来。毋庸置疑,Java 是你开发大型软件时最得心应手的利器或是你转行 IT 的入
门首选。
试题分析
例题 1:
Choose the three valid identiers from those listed below.
A. IDoLikeTheLongNameClass
B. $byte
C. const
D. _ok
E. 3_case
解答:A、B、D
点评:Java 中的标示符必须是字母、美元符($)或下划线(_)开头。关键字与保留字不能作为
标示符。选项 C 中的 const 是 Java 的保留字,所以不能作标示符。选项 E 中的 3_case 以
数字开头,违反了 Java 的规则。
例题 2:
How can you force garbage collection of an object?
A. Garbage collection cannot be forced
B. Call System.gc().
C. Call System.gc(), passing in a reference to the object to be garbage collected.
D. Call Runtime.gc().
E. Set all references to the object to new values(null, for example).
解答:A
点评:在 Java 中垃圾收集是不能被强迫立即执行的。调用 System.gc()或 Runtime.gc()静
态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项
B、D 不正确。选项 C 的错误在于,System.gc()方法是不接受参数的。选项 E 中的方法可
以使对象在下次垃圾收集器运行时被收集。
例题 3:
Consider the following class:
1. public class Test {
2. void test(int i) {
3. System.out.println(“I am an int.”);
4. }
5. void test(String s) {
6. System.out.println(“I am a string.”);
7. }
8.
9. public static void main(String args[]) {
10. Test t=new Test();
11. char ch=’a’;
12. t.test(ch);
13. }
14. }
Which of the statements below is true?(Choose one.)
A. Line 5 will not compile, because void methods cannot be overridden.
B. Line 12 will not compile, because there is no version of test() that rakes a
char argument.
C. The code will compile but will throw an exception at line 12.
D. The code will compile and produce the following output: I am an int.
E. The code will compile and produce the following output: I am a String.
解答:D
点评:在第 12 行,16 位长的 char 型变量 ch 在编译时会自动转化为一个 32 位长的 int 型,
并在运行时传给 void test(int i)方法。
例题 4:
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:
1. int a1 =2;
2. int a2 = 2;
3. int b = (++a1) * 2 – (a2--) * 3;
4. int c = (a1--) * 3 + (++a2) * 2;
What is the result?
A. b = 0 and c = 13
B. b = 0 and c = 12
C. b = 3 and c = 12
D. b = 3 and c = 13
解答:A
点评:一元运算符++,--只适用于变量,且变量位于运算符的哪一侧有不同的效果。当运算
符位于变量的左侧时,先++(或--)后运算,反之,先运算后++(或--)。
例题 6:
1. public class Test {
2. public static void main(String args[]) {
3. class Foo {
4. public int i = 3;
5. }
剩余11页未读,继续阅读
资源评论
My_Pass_Word
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功