当前位置:文档之家› 面向对象程序设计(JAVA)期末考试考试卷(A卷)

面向对象程序设计(JAVA)期末考试考试卷(A卷)

课程代码:座位号:大学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.InputStreamReader6.在Java中,由Java编译器自动导入,而无需在程序中用import导入的包是【】。

A.java.applet B.java.awt C.java.util D.ng7.下面程序定义了一个类,关于该类说确的是【】Abstract class abstractClass{……}A. 该类能调用new abstractClass(),方法实例化为一个对象B. 该类不能被继承C. 该类的方法都不能被重载D. 以上说法都不对8.已知有下面类的说明:public class X5_1_1 extends x{private float f =10.6f;int i=16;static int si=10;public static void main(String[] args) {X5_1_1 x=new X5_1_1();}}在main()方法中,下面哪条语句的用法是正确的?【】A.x.f B.this.si C .X5_1_1.i D.X5_1_1.f9.下列说法中,错误的一项是【】A.Thread类中没有定义run()方法 B.可以通过继承Thread类来创建线程C.Runnable接口中定义了run()方法 D.可以通过实现Runnable接口创建线程10.当一个Statement对象要执行一个查询类的SQL语句,调用的方法是【】A. executeQueryB.executeC. executeUpdatemit二、填空题(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 = 2.0;void show() {System.out.println("Class A: a=" + a + "\td=" + d);}}public class B extends A {float a = 3.0f;String d = "Java program.";void show() {super.show();System.out.println("Class B: a=" + a + "\td=" + d);}public static void main(String args[]) { A b=new B(); b.show(); }}程序的输出结果为:__ _2. abstract class A{abstract void show();abstract void show(int i);}Class B extends A{int x;void show(){System.out.print("x="+x++);}void show(int i){x=++i;System.out.println("x="+x++);}}Class AbstractDemo{public static void main(String[] args){B b=new B();b.show();b.show(10);}}程序的输出结果是:3.import java.util.*;public class test10 {public static void main(String args[]) {ArrayList<Integer> list=new ArrayList<Integer>();for(int i=0;i<10;i++) {list.add(i);}for(int k=list.size()-1;k>=0;k--) {int m=list.get(k);System.out.printf("%3d",m);}}}程序的输出结果是:4. class Speak{public void hello(){System.out.println("Hello!");}}public class test{public static void main(String args[]){Speak he=new Speak(){public void hello(){System.out.println("您好,很高兴认识您!");}};he.speak();}}程序的输出结果是:5.import java.io.* ;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(System.in));a[i] = Integer.parseInt(br.readLine( )); // 输入一个整数} catch ( IOException e ) { } ;for ( i = n-1 ; i >= 0 ; i ―― )sum=sum+I;System.out.print(sum);}}程序的功能是:四、程序改错题(2小题,共20分)1、假设数据库名为:oa,数据库连接采用windows ODBC数据源的方式,ODBC数据源名为misimport java.sql.*;public class Example14_1 {public static void main(String args[]) {Connection con;Statement st;ResultSet rs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动}catch(ClassNotFoundException e) {System.out.print(e);}try {con=DriverManager.getConnection("jdbc:odbc:oa","","");st=con.createStatement();rs=st.executeUpdate("SELECT * FROM employee order by number");while(rs.next()) {String number=rs.getString("number");String name=rs.getString("name");Date date=rs.getDate("birthday");double salary=rs.getDouble("salary");System.out.printf("%-4s",number);System.out.printf("%-6s",name);System.out.printf("%-15s",date.toString()); System.out.printf("%6s\n",salary);}con.close();}catch(SQLException e) {System.out.println(e);}}}2、i mport java.util.*;class Student extends Comparable {int english=0;String name;Student(int english,String name) {=name;this.english=english;}public int compareTo(Object b) {Student st=(Student)b;If(this.english==st.english){return 1;}elsereturn (this.english-st.english)*100;}}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,"三");mytree.add(st1);mytree.add(st2);mytree.add(st3);Iterator<Student> te=mytree.it ();while(te.hasNext()) {Student stu=te.next();System.out.println(""++" "+stu.english);} }}五、程序填空题(2小题,共20分)1.【】 class C{【】 void callme();void metoo {System.out.println(“类C的metoo()方法”);}}Class D【】C{void callme() {System.out.println(“重载C类的callme()方法”);}}public class Abstract {【】 main(String args[]){C c=【】D();C.callme();C.metoo();}}2.如下java源程序文件中,程序的功能是判断键盘输入的字符串是否是回文(字符串顺读和倒读都一样,则是回文。

相关主题