JavaOOP阶段小测试笔试题.pdf_第1页
JavaOOP阶段小测试笔试题.pdf_第2页
JavaOOP阶段小测试笔试题.pdf_第3页
JavaOOP阶段小测试笔试题.pdf_第4页
JavaOOP阶段小测试笔试题.pdf_第5页
已阅读5页,还剩6页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

使用 Java 实现面向对象编程 阶段测试 笔试试卷 一 选择题 共 25 题 每题 4 分 满分 100 分 1 在 Java 中 下列关于方法重载的说法中错误的是 A 方法重载要求方法名称必须相同 B 重载方法的参数列表必须不一致 C 重载方法的返回类型必须一致 D 一个方法在所属的类中只能被重载一次 2 给定 Java 代码如下所示 在横线处新增下列 方法 是对 cal 方法的重载 public class Test public void cal int x int y int z A public int cal int x int y float z return 0 B public int cal int x int y int z return 0 C public void cal int x int z D public void cal int z int y int x 3 在 Java 中 下面对于构造函数的描述正确的是 A 构造函数其主要功能是用来为对象成员变量赋初始值 B 构造函数的返回类型是 void C 构造函数和类有相同的名称 并且不能带任何参数 D 一个类可以定义多个构造函数 4 下面 Java 代码的运行结果是 class Penguin private String name null 名字 private int health 0 健康值 private String sex null 性别 public void Penguin health 10 sex 雄 System out println 执行构造方法 public void print System out println 企鹅的名字是 name 健康值是 health 性别是 sex public static void main String args Penguin pgn new Penguin pgn print A 企鹅的名字是 null 健康值是 10 性别是雄 B 执行构造方法 企鹅的名字是 null 健康值是 0 性别是 null C 企鹅的名字是 null 健康值是 0 性别是 null D 执行构造方法 企鹅的名字是 null 健康值是 10 性别是雄 5 下列选项中关于 Java 中封装的说法错误的是 A 封装就是将属性私有化 提供公有的方法访问私有属性 B 属性的访问方法包括 setter 方法和 getter 方法 C setter 方法用于赋值 getter 方法用于取值 D 类的属性必须进行封装 否则无法通过编译 6 public class Tetromino protected int move int x return 0 class T extends Tetromino 在处填入选项中的代码 使 T 类没有编译错误的是 A public int move int x return 0 B private int move int x return 0 C private int move long x return 0 D protected long move int x return 0 7 在 Java 中 以下程序编译运行后的输出结果为 public class Test int x y Test int x int y this x x this y y public static void main String args Test pt1 pt2 pt1 new Test 3 3 pt2 new Test 4 4 System out print pt1 x pt2 x A 6 B 3 4 C 8 D 7 8 在 Java 语言中 下列关于类的继承的描述 正确的是 A 一个类可以继承多个父类 B 一个类可以具有多个子类 C 子类可以使用父类的所有方法 D 子类一定比父类有更多的成员方法 9 Java 中 如果类 C 是类 B 的子类 类 B 是类 A 的子类 那么下面描述正确的是 A C 不仅继承了 B 中的公有成员 同样也继承了 A 中的公有成员 B C 只继承了 B 中的成员 C C 只继承了 A 中的成员 D C 不能继承 A 或 B 中的成员 10 给定一个 Java 程序 Test java 的代码如下所示 编译时 会出现以下 情况 class Parent public int count 第 1 行 return 0 public class Testextends Parent private int i public int count 第 2 行 return i 9 第 3 行 A 编译通过 B 在第 1 行引发编译错误 C 在第 2 行引发编译错误 D 在第 3 行引发编译错误 11 给定 Java 程序 Child java 的代码如下所示 则编译运行该类的结果是 class Parent Parent System out println parent public class Child extends Parent Child String s System out println s public static void main String args Child child new Child child A 输出 child B 输出 child parent C 输出 parent child D 编译错误 12 下列选项中关于 Java 中 super 关键字的说法错误的是 A super 关键字是在子类对象内部指代其父类对象的引用 B super 关键字不仅可以指代子类的直接父类 还可以指代父类的父类 C 子类可以通过 super 关键字调用父类的方法 D 子类可以通过 super 关键字调用父类的属性 13 分析如下所示的 Java 代码 则选项中的说法正确的是 class Parent public String name public Parent String pName this name pName public class Testextends Parent 1 public Test String Name 2 name hello 3 super kitty 4 A 第 2 行错误 Test 类的构造函数中参数名称应与其父类构造函数中的参数名相同 B 第 3 行错误 应使用 super 关键字调用父类的 name 属性 改为 super name hello C 第 4 行错误 调用父类构造方法的语句必须放在子类构造方法中的第一行 D 程序编译通过 无错误 14 以下关于 Object 类说法错误的是 A 一切类都直接或间接继承自 Object 类 B 接口亦继承 Object 类 C Object 类中定义了 toString 方法 D Object 类在 java lang 包中 15 给定 Java 代码如下所示 则编译运行后 输出结果是 class Parent public void count System out println 10 3 public class Childextends Parent public void count System out println 10 3 public static void main String args Parent p new Child p count A 1 B 1 0 C 3 D 3 3333333333333335 16 分析如下 Java 代码 如果想在控制台上输出 B 类的 test 方法 则在横线处应填入 class A public void test System out println A 类的 test 方法 class B extends A public void test System out println B 类的 test 方法 public static void main String args A Aa new B a test B Aa newA a test C B b new A b test D B b new B b test 17 编译运行如下 Java 代码 输出结果是 class Base public void method System out print Base method class Child extends Base public void methodB System out print Child methodB class Sample public static void main String args Base base new Child base methodB A Base method B Child methodB C Base method Child MethodB D 编译错误 18 下面关于 Java 接口的说法错误的是 A 一个 Java 接口是一些方法特征的集合 但没有方法的实现 B Java 接口中定义的方法在不同的地方被实现 可以具有完全不同的行为 C Java 接口中可以声明私有成员 D Java 接口不能被实例化 19 给定如下 Java 程序代码 在横线处加入 语句 可以使这段代码编译通过 interface Parent public int count int i public class Test implements Parent public int count int i return i 9 public static void main String args int i p count 20 A Test p new Test B Parent p new Test C Parent p new Parent D Test p new Parent 20 关于下列代码说法正确的是 public class Cell private final int id public Cell int id this id id public void updateId int id this id id public static void main String args Cell cell new Cell 1001 cell updateId 1002 System out println cell id A 编译错误 B 运行时异常抛出 C 运行后 cell 对象属性 id 的值没有改变 仍然是 1001 D 运行后 cell 对象属性 id 的值改变成新的值 1002 21 在 Java 中 关于 final 关键字的说法正确的是 C A 如果修饰局部变量 必须定义时初始化 B 如果修饰类 则该类只能被一个子类继承 C 如果修饰方法 则该方法不能在子类中被重写 D 如果修饰方法 则该方法所在的类不能被继承 22 关于下列代码说法正确的是 public interface A public void doSomething String thing interface B interface C extends A B interface D public void doIt String thing class AImpl implements C D public void doSomething String msg public void doIt String thing A 所有类和接口都编译成功 B 接口 A 编译失败 C 类 AImpl 编译失败 D 接口 C 编译失败 23 下列代码编译和运行的结果是 class A public void start System out println AStart public class B extends A public void start System out println B Start public static void main String args A new B start A 输出 AStart B 输出 B Start C 输出 AStart B Start D 编译错误 24 下列代码编译和运行的结果是 class Person String name public Person String name this name name class Employee extends Person String empNO 0000 public Employee String empNO this empNO empNO public class EmployeeTest public static void main String args Employee e new Employee 1109 System out println e empNO A 输出 0000 B 输出 1109 C 代码 public Employee String empNO 行 出现编译错误 D 抛出运行时异常 25

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论