面向对象程序设计(JAVA)期末考试试卷(A卷.doc
精选优质文档-倾情为你奉上课程代码: 座位号:新疆大学20 -20 学年度第二学期期末考试面向对象程序设计试卷姓名: 学号: 专业: 学院: 班级: 20 年 月 日题号一二三四五六总分得分专心-专注-专业得分评卷人 一、单选题(10小题,共10分)1下列选项中,用于在定义子类时声明父类名的关键字是 【 】 Ainterface B package C extends D class2在以下哪种情况下可以获得缺省构造器? 【 】A当作任何类的定义时 B当类没有其它构造器时C当定义至少一个构造器的时 D从不需要3如果局部变量和成员变量同名,如何在局部变量作用域内引用成员变量?【 】 A不能引用,必须改名,使它们的名称不相同 B在成员变量前加this,使用this访问该成员变量 C在成员变量前加super,使用super访问该成员变量 D不影响,系统可以自己区分4在异常处理中,如释放资源、关闭文件、关闭数据库等由哪个子句来完成【 】Atry子句 Bcatch子句 Cfinally子句 Dthrow子句 5下面哪个流类属于面向字符的输入流 【 】ABufferedWriter BFileInputStream CObjectInputStream DInputStreamReader6在Java中,由Java编译器自动导入,而无需在程序中用import导入的包是【 】。 Ajava.applet Bjava.awt Cjava.util Djava.lang 7下面程序定义了一个类,关于该类说法正确的是 【 】 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()方法中,下面哪条语句的用法是正确的? 【 】Ax.f Bthis.si CX5_1_1.i DX5_1_1.f9下列说法中,错误的一项是 【 】AThread类中没有定义run()方法 B可以通过继承Thread类来创建线程CRunnable接口中定义了run()方法 D可以通过实现Runnable接口创建线程10当一个Statement对象要执行一个查询类的SQL语句,调用的方法是 【 】A. executeQuery B.execute C. executeUpdate D.commit得分评卷人 二、填空题(10小题,共10分)1Java应用程序中有多个类时,java命令后的类名必须是包含了_方法的那个类的名字。2使用关键字 修饰的代码,称为同步代码段3对象创建完后,通过使用运算符 “ . ” , 对象可以实现对变量的访问和_的调用。 4Java中的非字符输出流都是抽象类_的子类。5Java语言使用_类及其子类的对象来表示线程6可以使用String类的_方法比较一字符串是否与字符串s相同。7如果在子类中想使用被子类隐藏的父类的成员变量或方法可以使用关键字_,使用本类中被局部变量隐藏的成员变量使用关键字_。8若子类对父类中的同名同参方法进行重新定义,我们称子类_了父类的同名方法。9Java中用类创建一个对象包括对象的声明和为对象_两个步骤。 得分评卷人 三、读程序题(5小题,共20分)1class 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 Aabstract void show();abstract void show(int i); Class B extends Aint x;void show()System.out.print("x="+x+);void show(int i)x=+i;System.out.println("x="+x+); Class AbstractDemopublic static void main(String args) B b=new B();b.show();b.show(10);程序的输出结果是: 3import 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 Speakpublic void hello()System.out.println("Hello!");public class testpublic static void main(String args)Speak he=new Speak()public void hello()System.out.println("您好,很高兴认识您!"); ; he.speak();程序的输出结果是: 5import java.io.* ; public class Reverse public static void main(String args ) int i , n =10 ,sum=0; int a = new int10; for ( i = 0 ; i < n ; i + ) try BufferedReader br = new BufferedReader( new InputStreamReader(System.in); ai = Integer.parseInt(br.readLine( ); / 输入一个整数 catch ( IOException e ) ; for ( i = n1 ; 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("%6sn",salary); con.close(); catch(SQLException e) System.out.println(e); 2、import java.util.*;class Student extends Comparable int english=0; String name; Student(int english,String name) this.name=name; this.english=english; public int compareTo(Object b) Student st=(Student)b; If(this.english=st.english) return 1;else return (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.name+" "+stu.english); 得分评卷人 五、程序填空题(2小题,共20分)1【 】 class C【 】 void callme();void metoo System.out.println(“类C的metoo()方法”); Class D【 】Cvoid callme() System.out.println(“重载C类的callme()方法”); public class Abstract 【 】 main(String args) C c=【 】D(); C.callme(); C.metoo(); 2如下java源程序文件中,程序的功能是判断键盘输入的字符串是否是回文(字符串顺读和倒读都一样,则是回文。如“abba”是回文)。方法palindrome判断字符串s是否是回文,若是回文,返回true,否则返回false。请仔细阅读程序,补充相应的语句,使整个程序能够正常运行。 import java.util.Scanner;public class J_Test 【 】int len = s.length();int h = 0, t = len - 1;while(h <= t) if(s.charAt(h) != s.charAt(t) Break;h+;t-;if(【 】) return true; Else return false;【 】 main(String args) Scanner scanner = new Scanner(【 】);System.out.println("请输入字符串: ");String s = 【 】; if(palindrome(s)System.out.println(s + " 是回文"); ElseSystem.out.println(s + " 不是回文");得分评卷人 六、编程题(3小题,共20分)1设计一个 moveable 可移动接口,其中包括启动、停止的方法 , 然后分别设计 2个类 , 即汽车 Car 、轮船 Ship 来实现该接口 , 最后设计一个测试程序来使用它们(6分)2编写一个JFrame程序,在两个文本框中输入两个整数,当用户按下“比较”按钮后,将标签中显示的“请先输入两个待比较的整数”,改为“两个整数中最大值是:x”,x是两个数中的最大值.(6分)3编写抽象图形类(Shape)和其子类三角形类(Triangle),图形类中定义抽象的求面积方法double getArea(),三角形重写此方法,能返回出三角形对象的面积。三角形类定义其带参构造方法,实现由参数对三边的初始化,要求对于不满足三边构成条件的,抛出异常,并在调用时,对异常做处理,输出异常信息。(8分)