java面向对象基础测试题,继承,封装,多态等测试题

上传人:简****9 文档编号:95603911 上传时间:2019-08-21 格式:DOC 页数:30 大小:15.77KB
返回 下载 相关 举报
java面向对象基础测试题,继承,封装,多态等测试题_第1页
第1页 / 共30页
java面向对象基础测试题,继承,封装,多态等测试题_第2页
第2页 / 共30页
java面向对象基础测试题,继承,封装,多态等测试题_第3页
第3页 / 共30页
java面向对象基础测试题,继承,封装,多态等测试题_第4页
第4页 / 共30页
java面向对象基础测试题,继承,封装,多态等测试题_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《java面向对象基础测试题,继承,封装,多态等测试题》由会员分享,可在线阅读,更多相关《java面向对象基础测试题,继承,封装,多态等测试题(30页珍藏版)》请在金锄头文库上搜索。

1、 JAVA面向对象基础测试题 提示:本题为第一阶段,JAVA面向对象基础部分练习题,包括对象,类,继承,封装,多态,接口,内部类等等,java核心基础,适合初学者对面向对象基础的知识进行测试,以便查漏补缺。 1. 程序执行的结果是:()。 01 public class Point 02 int y = 7; 03 public void step(int y) 04 y += y; 05 System.out.println(y); 06 07 public static void main(String args) 08 Point p = new Point(); 09 p.step(1

2、0); 10 11 A.14 B.20 C.10 D.17 正确答案:B解析: 2. 程序的执行结果是:()。 01 public class Question 02 private int num; 03 public static void main(String args) 04 Question q = new Question(); 05 q.num=13; 06 update(q); 07 System.out.println(q.num); 08 09 public static void update(Question q) 10 q.num=9; 11 12 A.13 B.9

3、 C.0 D.4 正确答案:B解析: 3. 程序执行的结果是:()。 01 public class Answer 02 public static void main(String args) 03 int score = 20; 04 Answer ans= new Answer(); 05 ans.add(score); 06 System.out.println(“ main: score = “ + score); 07 08 void add(int score) 09 System.out.println(“ add: score=“ + score+); 10 11 A. 1

4、add: score=21 2 main: score = 21 B. 1 add: score=20 2 main: score = 21 C. 1 add: score=21 2 main: score = 20 D. 1 add: score=20 2 main: score = 20 正确答案:D解析: 4. 下列代码编译或运行的结果是:()。 01 public class Snow 02 public String jump(int x, int y) 03 return “jump one“; 04 05 public String jump(int vals) 06 retur

5、n “jump two“; 07 08 public static void main(String args) 09 Snow s=new Snow(); 10 System.out.println(s.jump(4, 5); 11 12 A.public String jump(int vals) 行,编译出错 B.System.out.println(s.jump(4, 5);行,抛出运行时异常 C.输出:jump one D.输出:jump two 正确答案:C解析: 5. 关于下列代码说法正确的是:()。 01 public class Storm 02 public void fi

6、nd() 03 04 public String find() 05 return “find“; 06 07 public double find(int x) 08 return 2.0; 09 10 A.无编译错误 B.代码 public String find() 行,出现编译错误 C.代码 public double find(int x) 行,出现编译错误 D.代码 return “find“;行处出现编译错误 正确答案:B解析: 6. 请看下列代码: 01 class ClassA 02 class ClassB extends ClassA 03 class ClassC ex

7、tends ClassA 04 public class Test 05 public static void main(String args) 06 ClassA p0 = new ClassA(); 07 ClassB p1 = new ClassB(); 08 ClassC p2 = new ClassC(); 09 ClassA p3 = new ClassB(); 10 ClassA p4 = new ClassC(); 11 12 13 下列选项中放置在处,使程序编译正确的是:()。 A.p0 = p1; B.p1 =p2; C.p2 = p4; D.p2 = (ClassC)p

8、1; 正确答案:A解析: 7. 下列代码的运行结果是:()。 01 public class Animal 02 public String noise() 03 return “Animal“; 04 05 public static void main(String args) 06 Cat cat = null; 07 Animal animal = new Dog(); 08 if (animal instanceof Cat) 09 cat = (Cat) animal; 10 System.out.println(cat.noise(); 11 else 12 System.out

9、.println(“animal is not Cats instance“); 13 14 15 16 class Dog extends Animal 17 public String noise() 18 return “Dog“; 19 20 21 class Cat extends Animal 22 public String noise() 23 return “Cat“; 24 25 A.Animal B.Dog C.Cat D.animal is not Cats instance 正确答案:D解析: 8. 请看下列代码编译和运行的结果是:()。 1 public class

10、 Teacher 2 private String name=“sun“; 3 public static void main(String args) 4 Teacher teachers=new Teacher2; 5 System.out.println(teachers0.name); 6 System.out.println(teachers.length); 7 8 A.sun 2 B.null 2 C.null 1 D.运行时抛出NullPointerException异常 正确答案:D解析: 9. 下列代码编译和运行的结果是:()。 01 class Person 02 Str

11、ing name = “ “; 03 04 public Person(String name) 05 this.name = name; 06 07 08 09 class Employee extends Person 10 String empNO = “0000“; 11 12 public Employee(String empNO) 13 this.empNO = empNO; 14 15 16 17 public class EmployeeTest 18 public static void main(String args) 19 Employee e = new Emplo

12、yee(“1109“); 20 System.out.println(e.empNO); 21 22 A.输出:0000 B.输出:1109 C.代码public Employee(String empNO) 行,出现编译错误 D.抛出运行时异常 正确答案:C解析: 10. 下列代码编译和运行的结果是:()。 01 class A 02 public void start() 03 System.out.println(“A Start“); 04 05 06 public class B extends A 07 public void start() 08 System.out.print

13、ln(“B Start“); 09 10 public static void main(String args) 11 (A) new B().start(); 12 13 A.输出:A Start B.输出:B Start C.输出:A Start B Start D.编译错误 正确答案:B解析: 11. 关于下列代码说法正确的是:()。 01 public interface A 02 public void doSomething(String thing); 03 04 interface B 05 06 interface C extends A, B 07 08 interfac

14、e D 09 public void doIt(String thing); 10 11 class AImpl implements C ,D 12 public void doSomething(String msg) 13 public void doIt(String thing) 14 A.所有类和接口都编译成功 B.接口A编译失败 C.类AImpl编译失败 D.接口C编译失败 正确答案:A解析: 12. 在 Java 中,关于 final 关键字的说法正确的是:()。 A.如果修饰局部变量,必须定义时初始化 B.如果修饰类,则该类只能被一个子类继承 C.如果修饰方法,则该方法不能在

15、子类中被覆盖 D.如果修饰方法,则该方法所在的类不能被继承 正确答案:C解析: 13. 关于下列代码说法正确的是:()。 01 public class Cell 02 private final int id; 03 public Cell(int id) 04 this.id = id; 05 06 public void updateId(int id) 07 this.id = id; 08 09 public static void main(String args) 10 Cell cell = new Cell(1001); 11 cell.updateId(1002); 12 System.out.println(cell.id); 13 14 A.编译错误 B.运行时异常抛出 C.运行后,cell对象属性id的值没有改变,仍然是1001 D.运行后,cell对象属性id的值改变成新的值1002 正确答案:A解析: 14. 下列选项中,不属于Java 的访问控制修饰符的是:()。 A.private B.protected C.friendly D.public 正确答案:C解析: 15. 下面关于import, class和package的声明顺序正确

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号