面向对象程序设计(JAVA)期末考试试卷(A卷)
- 格式:doc
- 大小:320.00 KB
- 文档页数:12
面向对象程序设计(J A V A)期末考试试卷(A卷)本页仅作为文档页封面,使用时可以删除This document is for reference only-rar21year.March课程代码:座位号:新疆大学20 -20 学年度第二学期期末考试《面向对象程序设计》试卷姓名: 学号: 专业:学院: 班级:20 年月日一、单选题(10小题,共10分)1.下列选项中,用于在定义子类时声明父类名的关键字是【】A.interface B. package C. extends D. class2.在以下哪种情况下可以获得缺省构造器【】A.当作任何类的定义时 B.当类没有其它构造器时C.当定义至少一个构造器的时 D.从不需要3.如果局部变量和成员变量同名,如何在局部变量作用域内引用成员变量【】 A.不能引用,必须改名,使它们的名称不相同B.在成员变量前加this,使用this访问该成员变量C.在成员变量前加super,使用super访问该成员变量D.不影响,系统可以自己区分4.在异常处理中,如释放资源、关闭文件、关闭数据库等由哪个子句来完成【】A.try子句B.catch子句 C.finally子句 D.throw子句5.下面哪个流类属于面向字符的输入流【】A.BufferedWriter B.FileInputStream C.ObjectInputStream D.InputStreamReader 6.在Java中,由Java编译器自动导入,而无需在程序中用import导入的包是【】。
A. B. C. D.7.下面程序定义了一个类,关于该类说法正确的是【】Abstract class abstractClass{……}A. 该类能调用new abstractClass(),方法实例化为一个对象B. 该类不能被继承C. 该类的方法都不能被重载D. 以上说法都不对8.已知有下面类的说明:public class X5_1_1 extends x{private float f =;int i=16;static int si=10;public static void main(String[] args) {X5_1_1 x=new X5_1_1();}}在main()方法中,下面哪条语句的用法是正确的?【】A. B. C. D.9.下列说法中,错误的一项是【】A.Thread类中没有定义run()方法 B.可以通过继承Thread类来创建线程C.Runnable接口中定义了run()方法 D.可以通过实现Runnable接口创建线程10.当一个Statement对象要执行一个查询类的SQL语句,调用的方法是【】A. executeQueryC. executeUpdate二、填空题(10小题,共10分)1.Java应用程序中有多个类时,java命令后的类名必须是包含了___________方法的那个类的名字。
2.使用关键字修饰的代码,称为同步代码段3.对象创建完后,通过使用运算符“ . ” , 对象可以实现对变量的访问和____________的调用。
4.Java中的非字符输出流都是抽象类____________的子类。
5.Java语言使用___________类及其子类的对象来表示线程6.可以使用String类的__________方法比较一字符串是否与字符串s相同。
7.如果在子类中想使用被子类隐藏的父类的成员变量或方法可以使用关键字____________,使用本类中被局部变量隐藏的成员变量使用关键字____________。
8.若子类对父类中的同名同参方法进行重新定义,我们称子类___________了父类的同名方法。
9.Java中用类创建一个对象包括对象的声明和为对象____________两个步骤。
三、读程序题(5小题,共20分)1.class A {int a = 1;double d = ;void show() {"Class A: a=" + a + "\td=" + d);}}public class B extends A {float a = ;String d = "Java program.";void show() {();"Class B: a=" + a + "\td=" + d);}public static void main(String args[]) { A b=new B(); (); } }程序的输出结果为:__ _2. abstract class A{abstract void show();abstract void show(int i);}Class B extends A{int x;void show(){"x="+x++);}void show(int i){x=++i;"x="+x++);}}Class AbstractDemo{public static void main(String[] args){B b=new B();();(10);}}程序的输出结果是:3.import .*;public class test10 {public static void main(String args[]) {ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0;i<10;i++) {(i);}for(int k=()-1;k>=0;k--) {int m=(k);"%3d",m);}}}程序的输出结果是:4. class Speak{public void hello(){"Hello!");}}public class test{public static void main(String args[]){Speak he=new Speak(){public void hello(){"您好,很高兴认识您!");}};();}}程序的输出结果是:5.import .* ;public class Reverse{ public static void main(String args[ ]){ int i , n =10 ,sum=0;int a[ ] = new int[10];for ( i = 0 ; i < n ; i ++ )try {BufferedReader br = new BufferedReader(new InputStreamReader);a[i] = ( ));;public class Example14_1 {public static void main(String args[]) { Connection con;Statement st;ResultSet rs;try{("");;class Student extends Comparable {int english=0;String name;Student(int english,String name) {=name;=english;}public int compareTo(Object b) {Student st=(Student)b;If=={return 1;}elsereturn }}public class test {public static void main(String args[]) {TreeSet<Student> mytree=new TreeSet<Student>();Student st1,st2,st3,st4;st1=new Student(90,"赵一");st2=new Student(66,"钱二");st3=new Student(66,"孙三");(st1);(st2);(st3);Iterator<Student> te= ();while()) {Student stu=();""++" "+;} }}五、程序填空题(2小题,共20分)1.【】 class C{【】 void callme();void metoo {类C的metoo()方法”);}}Class D【】C{void callme() {重载C类的callme()方法”);}}public class Abstract {【】 main(String args[]){C c=【】D();();();}}2.如下java源程序文件中,程序的功能是判断键盘输入的字符串是否是回文(字符串顺读和倒读都一样,则是回文。
如“abba”是回文)。
方法palindrome判断字符串s是否是回文,若是回文,返回true,否则返回false。
请仔细阅读程序,补充相应的语句,使整个程序能够正常运行。
import class J_Test {【】{int len = ();int h = 0, t = len - 1;while(h <= t) {if(h) != (t)) Break;h++;t--;}if(【】)return true;Else return false;}【】 main(String[] args) {Scanner scanner = new Scanner(【】);"请输入字符串: ");String s = 【】;if(palindrome(s))+ " 是回文");Else+ " 不是回文");}}六、编程题(3小题,共20分)1.设计一个 moveable 可移动接口,其中包括启动、停止的方法 ,然后分别设计 2个类 , 即汽车 Car 、轮船 Ship 来实现该接口 , 最后设计一个测试程序来使用它们(6分)2.编写一个JFrame程序,在两个文本框中输入两个整数,当用户按下“比较”按钮后,将标签中显示的“请先输入两个待比较的整数”,改为“两个整数中最大值是:x”,x是两个数中的最大值.(6分)3.编写抽象图形类(Shape)和其子类三角形类(Triangle),图形类中定义抽象的求面积方法double getArea(),三角形重写此方法,能返回出三角形对象的面积。