面向对象测试题目

上传人:第*** 文档编号:33914168 上传时间:2018-02-19 格式:DOCX 页数:28 大小:13.53KB
返回 下载 相关 举报
面向对象测试题目_第1页
第1页 / 共28页
面向对象测试题目_第2页
第2页 / 共28页
面向对象测试题目_第3页
第3页 / 共28页
面向对象测试题目_第4页
第4页 / 共28页
面向对象测试题目_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《面向对象测试题目》由会员分享,可在线阅读,更多相关《面向对象测试题目(28页珍藏版)》请在金锄头文库上搜索。

1、马鞍山东校区 JSD1310 班级面向对象阶段测试试卷1.下面关于 Java 语言中方法的说法错误的是: A.方法调用时参数类型必须符合方法的定义 B.参数传递是值传递的方式 C.如果方法没有返回值必须声明返回为 void D.如果方法定义为返回 void,则方法中不能出现 return 语句 2.程序执行的结果是:public class Testint x = 12;public void method(int x) x += x;System.out.println(x);public static void main(String args) Test t = new Test();t

2、.method(5);A. 5 B.10 C.12 D.17 3.下面代码的输出结果是:public class Main public static void main(String args) int n = 100;int m = 200;System.out.println(f(n,m);System.out.println(n);public static int f(int m, int n) n = m+n;return n;A.300 300B.100 100C.300 100D.100 300 4.程序执行的结果是:public class Test public stati

3、c void main(String args) int x = 6;Test p = new Test();p.doStuff(x);System.out.println( main: x = + x);void doStuff(int x) System.out.println( doStuff:x = + x+); A.doStuff:x =7main: x = 7 B.doStuff:x =7main: x = 6 C.doStuff:x =6main: x = 7 D.doStuff:x =6main: x = 6 5.指出下列程序运行的结果public class Example

4、String str=new String(tarena); charch=a,b,c; public static void main(String args) Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+ and ); System.out.print(ex.ch); public void change(String str,char ch) str=test ok; ch0=g; A.tarena and abc B.tarena and gbc C.test ok and abc

5、 D.test ok and gbc 6.关于 Java 对象的删除,下列说法正确的是:A.必须由程序员完成对象的清除 B.Java 把没有引用的对象作为垃圾收集起来并释放 C.只有当程序中调用 System.gc()方法时才能进行垃圾收集 D.Java 中的对象都很小,一般不进行删除操作 7.下列代码编译或运行的结果是:public class Foo public String doit(int x, int y) return a;public String doit(int vals) return b;public static void main(String args) Foo

6、f=new Foo();System.out.println(f.doit(4, 5); A. public String doit(int vals) 行,编译出错 B. System.out.println(f.doit(4, 5);行,抛出运行时异常 C.输出:a D.输出:b 8.下列代码的输出结果是:public class Test public void print(char c) System.out.println(c);public void print(int i) System.out.println(i);public void print(double d) Sys

7、tem.out.println(d);public void print(String s) System.out.println(s);public static void main(String args) Test test=new Test();test.print(5); A.c B.i C.d D.s 9.程序执行的结果是:public class Test String name=Tom;public Test(String name)name=name;public static void main(String args)Test t = new Test(Jack);Sys

8、tem.out.println(t.name);A.null B.Tom C.Jack D. 10.关于下列代码说法正确的是:public class Foo public int add(int a, int b) return a + b;public static void main(String args) Foo foo = null;System.out.println(foo.add(10, 20); A. 编译错误 B. 正常运行,但无结果输出 C. 运行输出:30 D. 运行时抛出 NullPointerException 异常 11.给出下面的代码段:public clas

9、s Baseint w, x, y, z;public Base(int a, int b)x=a; y=b;public Base(int a, int b, int c, int d)w=d;z=c;在处写下如下代码,正确的是 :A.Base(a, b); B.super(a,b); C.x=a, y=b; D.this(a,b); 12.下列代码运行的结果是:class Foo public int a;public Foo() a = 3;public void addFive() a += 5;class Bar extends Foo public int a;public Bar

10、() a = 8;public void addFive() this.a += 5;public class TestFoo public static void main(String args) Foo foo = new Bar();foo.addFive();System.out.println(Value: + foo.a);A.Value: 3 B.Value: 8 C.Value: 13 D.Value: 18 13.下列代码编译和运行的结果是:class Person String name = No name;public Person(String nm) name =

11、nm;class Employee extends Person String empID = 0000;public Employee(String id) empID = id;public class EmployeeTest public static void main(String args) Employee e = new Employee(4321);System.out.println(e.empID); A.输出:0000 B.输出:4321 C.代码 public Employee(String id) 行,出现编译错误 D.抛出运行时异常 14.下列代码的运行结果是:

12、public class Animal public String noise() return peep;public static void main(String args) Cat cat =null;Animal animal = new Dog();if (animal instanceof Cat) cat = (Cat) animal;System.out.println(cat.noise();elseSystem.out.println(animal is not Cats instance);class Dog extends Animal public String n

13、oise() return bark;class Cat extends Animal public String noise() return meow; A.peep B.bark C.meow D.animal is not Cats instance 15.请看下列代码:public class Blip protected int blipvert(int x) return 0;class Vert extends Blip 在处填入选项中的代码,使 Vert 类没有编译错误的是:A.public int blipvert(int x) return 0; B.private in

14、t blipvert(int x) return 0; C.private int blipvert(long x) return 0; D.protected long blipvert(int x) return 0; 16.下列选项中,不属于 Java 的访问修饰符的是:A.private B.protected C.friendly D.public 17.在 Java 中,关于 static 关键字的说法错误的是: A.static 可以修饰方法 B.static 可以修饰变量 C.static 可以修饰代码块 D.static 修饰的方法,在该方法内部可以直接访问非静态的成员变量

15、18.下列类的定义,错误的是: A.public class Test extends Object B.final class Operators C.class Point D.void class Point 19.在 Java 中,关于 final 关键字的说法正确的是: A.如果修饰局部变量,必须初始化 B.如果修饰类,则该类只能被一个子类继承 C.如果修饰方法,则该方法不能在子类中被覆盖 D.如果修饰方法,则该方法所在的类不能被继承 20.关于下列代码说法正确的是:public class ItemTest private final int id;public ItemTest(int id) this.id = id;public void updateId(int newId) id = newId;public static void main(String args) ItemTest fa = ne

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

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