收藏 分销(赏)

java基础测试题3.doc

上传人:xrp****65 文档编号:8365748 上传时间:2025-02-10 格式:DOC 页数:4 大小:34.50KB 下载积分:10 金币
下载 相关 举报
java基础测试题3.doc_第1页
第1页 / 共4页
java基础测试题3.doc_第2页
第2页 / 共4页


点击查看更多>>
资源描述
java基础测试题3 1. Test.java程序如下:, 1. public class Test { 2. public static void main(String [] abc) { 3. unsigned int x = 10; 4. for (int y=0; y<5; y++, x--) 5. System.out.print(" " + x); 6. } 7. } 指出哪一行有错误? (Choose one.) A. 第2行 B. 第3行 C. 第4行 D.没有错误 答案:B 解析:unsigned 这个是在C语言中才有的 2. TestCount.java程序如下: 1. interface Count { 2. short counter = 0; 3. void countUp(); 4. } 5. public class TestCount implements Count { 6. 7. public static void main(String [] abc) { 8. TestCount t = new TestCount(); 9. t.countUp(); 10. } 11. public void countUp() { 12. for (int x = 6; x>counter; x--, ++counter) { 13. System.out.print(" " + counter); 14. } 15. } 16. } 此程序的错误在于? (Choose one.) A. 第2行 B. 第7行 C. 第8行 D. 第12行 答案:D 解析:考查接口和final 参看下面的代码 package a; public class test2 { interface Count {//接口只可以定义static final成员变量 public static final short counter = 0;//public static final //这个是默认有的. void countUp(); } } package a; import a.test2.Count; public class test3 implements Count { public static void main(String[] abc) { test3 t = new test3(); t.countUp(); } public void countUp() { for (int x = 6; x > counter; x--, ++counter) { //这里的counter //已经被改变了.所以错了 //回顾final,finally, //finalize 的用法 /* * final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。 */ System.out.print(" " + counter); } } } 3. Test3.java程序如下: 1. public class While { 2. public void loop() { 3. int x= 0; 4. while ( 1 ) { 5. System.out.print("x plus one is " + (x + 1)); 6. } 7. } 8. } 此程序编译时将会提示哪些行有语法错误?(Choose one.) A. 第1行. B. 第1、4行. C. 第1、4、5行 D. 第4行. 答案:B 解析:类的命名不能使用关键字 ,while后面只能是true或者是false。其中第五行代码没有问题,它可以相当于("x=”+x) 4. ChildClass.java程序如下: 1. class ParentClass { 2. public int doStuff(int x) { 3. return x * 2; 4. } 5. } 6. 7. public class ChildClass extends ParentClass { 8. public static void main(String [] args ) { 9. ChildClass cc = new ChildClass(); 10. long x = cc.doStuff(7); 11. System.out.println("x = " + x); 12. } 13. 14. public long doStuff(int x) { 15. return x * 3; 16. } 17. } 进行编译时,哪一行将出错?(Choose one.) A. 第3行 B. 第10行 C. 第14行. D. 第15行. 答案:C 解析:long 的最大值是263-1,最小值是-263。 // long 的类型应该改为int 这道题的结果为21。 5. TestObj.java程序如下: 1.public class TestObj { 2. public static void main (String [] args) { 3. Object o = new Object() { 4. public boolean equals(Object obj) { 5. return true; 6. } 7. } 8. System.out.println(o.equals("Fred")); 9. } 10.} 如想正确编译,需要如何更正?(Choose one.) A. 无需要更正。编译时,没有错误 B. 删除第4、5、6行 C. 删除第8行 D. 添加“;”在第7行末尾 答案:D 解析:我不能理解,还望哪位高手帮忙分析。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服