收藏 分销(赏)

2024年java基础笔试测试题及答案.doc

上传人:快乐****生活 文档编号:8186179 上传时间:2025-02-07 格式:DOC 页数:15 大小:87.54KB 下载积分:8 金币
下载 相关 举报
2024年java基础笔试测试题及答案.doc_第1页
第1页 / 共15页
2024年java基础笔试测试题及答案.doc_第2页
第2页 / 共15页


点击查看更多>>
资源描述
Java 一章 至 五章 考试 一.填空题(8分) 1. 面对对象的三大标准是( 封装 ),( 继承 )和( 多态 ).2分 2. 假如想在对象实例化的同时就初始化组员属性,则使用( 结构函数 ).2分 3. ( 实体)措施和( 结构 )措施不能修饰为abstract?2分 二.选择题(60分) 1) 在Java语言中,下列(a,d)是不满足命名规范的变量名。(选择二项) a) 姓名 b) $Name c) _instanceof d) instanceof 2) 下列Java代码片段的输出成果是( a )。 char c='a'; int i=c; float f=i; byte b=(byte)c; System.out.println(c+","+i+","+f+","+b); a) 编译错误 b) a,97,97,97 c) a,97,97.0,97 d) a,97,97.0f,97 3) 下列Java代码中,空白处的代码是(b,c )。(选择两项) public interface Fee{ public float calLabFee(float unitPrice, float time); } public class FeeImpl implements Fee { public float calLabFee(float unitPrice, float time){ return unitPrice * time; } } public class FeeInterfaceTest { public static void main(String[] args){ ________________ Float labFee = fee.calLabFee(400.00,5); } } a) Fee fee = new Fee (); b) Fee fee = new FeeImpl(); c) FeeImpl fee = new FeeImpl(); d) FeeImpl fee = new Fee (); 4) 在JAVA语言中,在包Package1中包括包Package2,类Class_A直接从属于包Package1,类Class_C直接从属于包package2.在类Class_B要应用Class_A的A 和Class_C的措施B ,你需要( a, b)语句。(选择两项) a) import package1.*; b) import package1.package2.*; c) import package2.*; d) import package2.package1.*; 5) int[] my_Array; my_Array=new int[5]; for(int count=0;count<=5;count++) System.out.println(my_Array[count]); 正确的运行成果是( d) a) 将1,2,3,4,5输出到屏幕 b) 将0,1,2,3,4输出到屏幕 c) 将0,1,2,3,4,5输出到屏幕 d) 将出现运行时异常 6) 在java 语言中,假如你有下面的类定义:( b) abstract class Shape{ abstract void draw(); } class Square extends Shape{}.(选择一项) a) 一切成功编译 b) Shape能够编译,Square不能编译 c) Square能够编译,Shape不能编译 d) Square,Shape都不能编译 7) 在JAVA编程中,如下( b)命令用来执行JAVA类文献 a) javac b) java c) appletviewer d) 以上所有选项都不正确 8) 编译并运行下面的Java程序: (c) class A{   int var1=1;   int var2;   public static void main(String[] args){     int var3=3;     A a=new A(); System.out.println(a.var1+a.var2+var3); } } a) 0 b) 4 c) 3 d) 代码无法编译,因为var2根本没有被初始化 9) 在Java 语言中,下面有关结构函数的描述正确的是( d)。(选择一项) a) 类必须有显式结构函数 b) 它的返回类型是void c) 它和类有相同的名称,但它不能带有任何参数 d) 以上皆非 10) 在java语言中,类Worker是类Person的子类,Worker的结构措施中有一句"super()", 该语句( c ).(选择一项) a) 调用类Worker中定义的super()措施 b) 调用类Person中定义的super()措施 c) 调用类Person的结构函数 d) 语法错误 11) 研究下面的JAVA代码: switch(x){ case1: System.out.println(1); case2: case3: System.out.println(3); case4: System.out.println(4); } 当x=2时,运行成果是(d ).(选择一项) a) 没有输出任何成果 b) 输出成果为3 c) 输出成果为3和4 d) 输出成果为1,3和4 12) 在//point x处的哪些申明是句法上合法的? (选择两项) class Person { private int a; public int change(int m){return m;} } public class Teacher extends Person { public int b; public static void main(String arg[]){ Person p=new Person(); Teacher t=new Teacher(); int i; //point x } } (c, d ) a) i=m; b) i=b; c) i=p.a; d) i=p.change(30); e) i=t.b; 13) 下面有关继承的哪些论述是正确的?(选择两项) (a, d) a) 在java 中只允许单一继承 b) 在java中一个类只能实现一个接口 c) 在java中一个类不能同时继承一个类和实现一个接口。 d) java的单一继承使代码更可靠。 14) public class test3{ public static void main(string args[ ]) { for (int i=0;i<3; i ++){ for(int j=3;j >=0;j--){ if(i= =j) continue; system.out.printin(“i=”+i+“j=” +j); } } } }(a,d,b) (选择三项) a) i =0 j=3 b) i =0 j=0 c) i =2 j=2 d) i =0 j=2 e) i =1 j=2 15) ( d )修饰符允许对类组员的访问不依赖于该类的任何对象 a) abstract b) static c) return d) public 16) 研究下面的Java代码: public class testException{ public static void main(String args[]){ int a[]={0,1,2,3,4}; int sum=0; try{ for(int i=1;i<6;i++) sum=sum+a[i]; System.out.println("sum="+sum); } catch(ArrayIndexOutOfBoundsException e){ System.out.println("数组越界"); } finally{ System.out.println("程序结束");} } } 输出成果将是( b )。 (选择一项) a) 10 数组越界 程序结束 b) 10 程序结束 c) 数组越界 程序结束 d) 程序结束 17) 给定如下java代码: public class Test { public static void main(String[] args) { int output=10; boolean b1=false; if((b1==true)&&((output+=10)==20)) { System.out.println(“Equal”+output); }else { System.out.println(“Not equal”+output); } } }( c ) a) Equal 10 b) Equal 20 c) Not equal 10 d) Not equal 20 18) 给定如下java代码,编译运行后将会输出(c )(选择一项) public class Test { public static void main(String[] args) { int a = 5; System.out.println((a%2==1)?(a+1)/2:a/2); } } a) 1 b) 2 c) 3 d) 4 19) public class Test extends Parent { public int count(){ return 1%9; } public static void main(String[] args) { System.out.println(count()); } } 编译运行成果是( c )(选择一项) a) 编译错误 b) 运行时出现例外 c) 正常运行,输出1 d) 正常运行,输出0 20) 已知A类被打包在packageA , B类被打包在packageB ,且B类被申明为public ,且有一个组员变量x被申明为protected控制方式 。C类也位于packageA包,且继承了B类 。则如下说话正确的是(c)(选择一项) a) A类的实例不能访问到B类的实例 b) A类的实例能够访问到B类一个实例的x组员 c) C类的实例能够访问到B类一个实例的x组员 d) C类的实例不能访问到B类的实例 三.问答题(22分) 1.措施重载要符合什么条件?4分 1,措施名相同 2,参数类型不一样(参数个数不一样,或者参数类型不一样,或者类型和参数都不一样) 3,与返回类型无关 2.修饰组员变量的四种访问权限是哪些,分别在哪些地方能够访问?4分 1,public,所有都可访问 2,protected,子类和同包可访问 3,private,本类可访问 4,默认,同包可访问 3.super核心字的作用?它什么时候用?3分 1,放在子类结构函数的第一行,显示调用父类的结构函数 2,super.措施名,调用父类的措施 3,super.属性名,调用父类的组员属性 4.措施重写要符合什么条件?和措施重载有什么区分?5分 1,有继承 2,措施名,参数,返回类型都相同 与重载的区分: 重载是参数不一样,与返回类型无关 4. 多态分哪两种?前提条件分别是什么?3分 1, 运行时多态,前提是有继承,子类重写父类的措施,并且父类的引用指向子类的应用 2, 编译时多态, 6. final有哪些作用?分别有哪些注意事项?3分 1, 类不能被继承,措施不能被重写 2, 措施中不能用this核心字 四.附加题:(10) 抽象类、继承、接口综合 设计一个系统: XXX门的实现过程: 流程: 设计一张抽象的门Door,那么对于这张门来说,就应当拥有所有门的共性,开门openDoor()和关门closeDoor();然后对门进行另外的功效设计,防盗--theftproof()、防水--waterproof()、防弹--bulletproof()、防火、防锈…… 要求:利用继承、抽象类、接口的知识设计该门 public interface Function{ Public void theftproof(); public void waterproof(); public void bulletproof(); public void fireproof(); public void rustproof(); } public abatract Door{ public void openDoor(); public void closeDoor(); } public class theftProofDoor extends Door,implements Function { public void openDoor(){ System.out.println(“开门。。。。”) } public void closeDoor(){ System.out.println(“关门。。。。”) } public void theftproof(){ System.out.println(“这是防盗门。。。。”) } public void bulletproof(){ } public void waterproof(){ } public void fireproof(){ } public void rustproof(){ } } public class waterProofDoor extends Door, implements Function { public void openDoor(){ System.out.println(“开门。。。。”) } public void closeDoor(){ System.out.println(“关门。。。。”) } public void theftproof(){ } public void bulletproof(){ } public void fireproof(){ } public void rustproof(){ } public void waterproof(){ System.out.println(“这是防水门。。。。”) } } public class bulletProofDoor extends Door,implements Function { public void openDoor(){ System.out.println(“开门。。。。”) } public void closeDoor(){ System.out.println(“关门。。。。”) } public void theftproof(){ } public void waterproof(){ } public void fireproof(){ } public void rustproof(){ } Public void bulletproof(){ System.out.println(“这是防弹门。。。。”) } } public class fireProofDoor extends Door,implements Function { public void openDoor(){ System.out.println(“开门。。。。”) } public void closeDoor(){ System.out.println(“关门。。。。”) } public void theftproof(){ } public void waterproof(){ } public void fireproof(){ System.out.println(“这是防火门。。。。”) } public void rustproof(){ } Public void bulletproof(){ } } public class rustProofDoor extends Door,implements Function { public void openDoor(){ System.out.println(“开门。。。。”) } public void closeDoor(){ System.out.println(“关门。。。。”) } public void theftproof(){ } public void waterproof(){ } public void fireproof(){ } public void rustproof(){ System.out.println(“这是防锈门。。。。”) } Public void bulletproof(){ } }
展开阅读全文

开通  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 

客服