南昌大学JAVA期末复习题_第1页
南昌大学JAVA期末复习题_第2页
南昌大学JAVA期末复习题_第3页
南昌大学JAVA期末复习题_第4页
南昌大学JAVA期末复习题_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

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

文档简介

1、精选优质文档-倾情为你奉上1、  填空题  1 对象之间可能存在的关系有三种:_包含_、_继承_和_关联_。 2 面向对象的软件开发过程大体可分为 _面对对象分析、_面对对象设计_和_面对对象测试_三个阶段。 3 Java 语言中实现多态的方法有 _继承_、_方法重载_ 和_成员覆盖_。 4 Java 语言具有可移植性、高性能、健壮性、安全性和独立于体系结构的_跨平台_特点。  5 JAVA语言规定object类是J

2、AVA 程序中所有类的父类,当前类的构造方法用this()表示,直接父类的构造方法用super()表示。 6 如果一个Java  Applet 源程序文件只定义有一个类,该类的类名为MyApplet,则类MyApplet 必须是Applet类的子类并且存储该源程序文件的文件名为   MyApplet.java。 7 如果一个Java  Applet 程序文件中定义有3 个类,则使用Sun 公司的JDK 编译器java

3、c.exe编译该源程序文件将产生 3 个文件名与类名相同而扩展名为.class  的字节码文件。 8 在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用2 字节内存空间,这样,无论是中文字符还是英文字符,都是占用 2字节内存空间。 10 Applet 是能够嵌入到HTML 格式的文件中,并能够在浏览器中运行的Java。 11 在Java 中,线程的模型就是一个CPU、程序代码和数据的封装体。 12

4、 键盘键入字符串并在计算机屏幕上显示,这时的数据源是键盘。 13 JAVA语言是第一个语言本身就支持线程的编程语言,其对线程的支持主要通过java.lang.Thread类和java.lang.Runnable接口来实现。 14 设有数组定义:int   MyIntArray  =  10 , 20 , 30 , 40 , 50 , 60 , 70;

5、0;  则执行以下几个语句后的输出结果是120 。 int  s = 0  for  ( int  i = 0  i < MyIntArray.length  i + + )       if  ( i % 2&#

6、160;= = 1 )    s += MyIntArrayi  System.out.println( s ); 15 JVM 是Java Virtual Machine的缩写; AWT 是abstrac window toolkit的缩写。 16 单重继承是指只有一个父类的继承;多重继承是指有一个以上父类的继承;Java 语言出于安全、可靠的考虑,仅支持单重继承;但Java 

7、;语言可通过接口来实现多重继承。 17 Java 中构成图形用户界面的元素和成分可分为 _容器_、_控制组件_和_用户自定义_等三类。 18 一个线程的完整生命周期包括如下 5 种状态 _新生_、_就绪_、_运行_、_阻塞_和_死亡_。 19 Java 中实现多线程的图径有2 种,一种是_继承thread类_,另一种是_Runnable接口。 20 任何一个Java 程序都默认引入了一个包,这个包的名字叫java.lang。 

8、21 Java 语言中,有一个类是所有类或接口的父类,这个类的名称是object。  22 下列程序的功能是创建了一个显示5 个"Hello!"的线程并启动运行,请将程序补充完整。 public class ThreadTest extends Thread      public static void main(String args)  &#

9、160;      ThreadTest t=new _ThreadTest()_;         t.start();      public void run()int i=0;         while(true)System.out.pr

10、intln("Hello!");            if (i+=4)  break;                 23 Java 中访问限定符有public、private_、protected和default 等。&#

11、160;24 事件处理机制中包含以下3 个部分事件源、事件对象和事件监听器,JAVA2 的事件处理模型被称为委托事件处理模型。 25 JAVA线程在其生命周期中会处在不同的状态,包括运行、暂停、同步和挂起 。 26 图形用户界面由容器和组件组成。 27 表示可直接对数据源进行读写操作的流称为 节点流 。 28 如果要将捕获到的异常在当前方法中处理,应该使用try-catch-final语句来捕获一个或多个异常。 29 抽象 方法是一种仅

12、有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。final方法是不能被当前类的子类重新定义的方法。 30 创建一个名为 MyPackage 的包的语句是   packge MyPackage  ,该语句应该放在程序的位置为:  源代码 的第一行              二、 简答与程序分析题 1 

13、;简述程序、进程与线程的差别。  2 简述方法重载与方法覆盖的区别 方法的覆盖和重载是Java多态性的不同表现。覆盖是父类与子类之间多态性的一种表现,重载是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被覆盖。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被“屏蔽”了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载。重载的方法是可以改变返回值的类型。3 阅读以下程序:(本题3 分) class Fat

14、herClass   public FatherClass()    System.out.println("FatherClass Create");       public class ChildClass extends FatherClass    public ChildClass()  

15、0; System.out.println("ChildClass Create");      public static void main(String args)    FatherClass fc = new FatherClass();    ChildClass cc = new Ch

16、ildClass();       程序运行结果是FatherClass CreateFatherClass CreateChildClass Create_ 4 阅读以下程序: class MyThread extends Thread  public void run()   System.out.println("MyThread: run()"); 

17、   public void start()   System.out.println("MyThread: start()");    class MyRunnable implements Runnable  public void run()   System.out.println("MyRunnable: run()&

18、quot;);    public void start()   System.out.println("MyRunnable: start()");    public class MyTest   public static void main(String args)   MyThread myThre

19、ad  =  new MyThread();   MyRunnable myRunnable = new MyRunnable();   Thread thread  =  new Thread(myRunnable);   myThread.start();   thread.start();   

20、; 此程序的运行结果是_MyThread:start()MyRunnable:run() 5 阅读程序,写出程序的运行结果 import java.util.Scanner; public class TestThrowException  public static void main(String args)   TestThrowException t = new TestThro

21、wException();   System.out.print("请输入您的年龄:");   System.out.println("您的年龄:" + t.inputAge();      public int inputAge()   int result = -1;   Scanner sca

22、n = new Scanner(System.in);   while(true)    try     result = scan.nextInt();     if(result<0 | result>130)      Exce ption me =&

23、#160;new Exception("年龄超出合理范围!");      throw me;           break;         catch(Exception e1)     Sy stem.out.print(

24、e1.getMessage() + "请重新输入:");     con tinue;           return result;     输入 14 5 时 程序运行结果_ 6 阅读以下程序: import java.io.*; p

25、ublic class  ReadLineT est   public static void main(String   ar gs) throws IOException    BufferedReader  b=new  BufferedReader (new InputStreamReader(System.in); &

26、#160;  String s;    System.out.flush();    s=b.readLine();    System.out.println(s);     运行以上程序,若从键盘输入: Hello< 回车> 阅读以下程序,输出结果为       Hello 

27、;         。 7 阅读以下程序    import    java.io.*; public    class   ATest    public   static   void   m&#

28、160;ain(String args)     SubClass    sb = new   SubClass( );                      System .out.println(sb.

29、funOfMod( );      class    Su perClass    int  a = -10 , b =-3     class  Sub Class  extends  SuperClass   

30、60;int  funOfMod( )   return   a%b;       程序运行结果为_-1_ 8 阅读以下程序: class  A      public static void main(String args)  String s,s1=&q

31、uot;"   char c;   s=args0;   for (int i=0;i<s.length();i+)    c=s.charAt(i);    if(c>=' a' && c<='z')     s1=s1+Character&

32、#160;.toUpperCase(c);    else  s1=s1+Character.toLowerCase(c);       System.out.println(s1);    若在dos 命令行输入:java  A   hELLO , 则输出为       

33、60; hELLO                      。 9 阅读以下程序:(本题3 分) public  class  C     public  static  void 

34、60; m ain(String  ar gs )          int   i , j     int  a  =  2,1,4,8,9,5,3;       for  ( 

35、i = 0  i < a.length-1; i + )         int  k = i;        for  ( j = i  j < a.length   

36、;j+ )         if  ( aj<ak )  k = j;       int  tem p =ai;        ai = ak;     

37、;   ak = temp;        for  ( i =0  i<a.length; i+ )        System .out.print(ai+"  ");       

38、;  System.out.println( );                                          程序运行结果为&

39、#160;       1 2 3 4 5 6 7 8 9                10 阅读程序,写出程序的运行结果 public class Person   String name;  int age;  public 

40、;String getInfo()         return "Name:"+ name + "t" +"age:"+ age;     public class Student extends Person   String school;&#

41、160;  public String getInfo()         return "Name:"+ name + "tAge:"+ age + "tSchool:" + school;     public class Test &

42、#160;public static void main(String args)        Person p = new Person();         = "Tom"        p.age = 

43、;18;        System.out .println(p.getInfo();                S tudent s = new Student();         =&#

44、160;"Billy"        s.age = 34;        s.school = "THU"        System.out.println( s.getInfo();    程序运行结果_ 

45、0;11 阅读程序,写出程序的运行结果 class Animal  protected int i = 1;    class Person extends Animal  protected int i = 2;  /用于测试同名属性,无现实含义  private String name = &q

46、uot;Tom"  private int age = 9;  public String getInfo()   return "Name:" + name + "tAge:" + age;      public void testI()  &#

47、160;System.out.println(super.i);   System.out.println(i);      class Student extends Person  private int i = 3;  private String school = "THU"  public Stri

48、ng getInfo()   return super.getInfo() + "tSchool:" + school;     public void testI()   System.out.println(super.i);   System.out.println(i);      publ

49、ic class Test  public static void main(String args)   Person p = new Person();   System.out.println(p.getInfo();    p.testI();   Student s = new Student();

50、   System.out.println(s.getInfo();   s.testI();       程序运行结果_ 12 阅读程序,写出程序的运行结果 interface Runner    public void run();   interface Swimmer   public

51、60;void swim();   abstract class Animal     public abstract void eat();     class Person extends Animal implements Runner,Swimmer    public void run()

52、     System.out.println("I am running, to the sea!");        public void swim()      System.out.println("I am swimming, to the isl

53、and!");      public void eat()     System.out.println("I am eating!");      public class Test  public static void main(String args) 

54、60; Test t = new Test();   Person p = new Person();   t.m1(p);   t.m2(p);   t.m3(p);    public void m1(Runner f)     f.run(); 

55、0;   public void m2(Swimmer s)    s.swim();    public void m3(Animal a)    a.eat();    程序运行结果_ 13 阅读程序,写出程序的运行结果 public class Person implements&#

56、160;Cloneable  private String name;  private int age;  public Person(String name,int age)    = name;   this.age = age;     public void setAge

57、(int age)   this.age = age;     public void setName(String name)    = name;      public void display()   System.out.println("Name:"

58、 + name + "tAge:" + age);     public Object clone()   Person p = null;         try           &#

59、160; p = (Person)super.clone();         c atch(CloneNotSupportedException e)             e.printStackTrace();         &#

60、160;        return p;       public class Book implements Cloneable  String bookName;  double price;  Person author;  public Book(String 

61、;bn,double price,Person author)   bookName = bn;   this.price = price;   this.author = author;      public Object clone()   Book b = null; &

62、#160;       try             b = (Book)super.clone();                     c atch(

63、CloneNotSupportedException e)             e.printStackTrace();                  b.author = (Person)author.clone();  

64、0;      return b;       public void display()   System.out.print(bookName + "t" + price + "t")    author.display();   &#

65、160; public class TestDeepCopy  public static void main(String args)   Book b1 = new Book("Java 编程",30.50,new Person("张三",34);   Book b2 = (Book)b1.clone();

66、0;  b2.price = 44.0;   b2.author.setAge(45);   b2.author.setName("李四");   b2.bookName = "Java 开发"   b1.display();    b2.display();     程序运行结

67、果_ 14 阅读程序,写出程序的运行结果 import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter;  public class MyAdapter extends WindowAdapter  public void windowClosing(WindowEvent e)   System.exit(1);&#

68、160;     import java.awt.Frame; public class TestAdapter     public static void main(String args)   Frame f = new Frame("Java Gui");   f.setSize(

69、150,150);   MyAdapter m = new MyAdapter();   f.addWindowListener(m);   f.setVisible(true);        程序运行的用户界面如上图, 程序运行效果为_ 15 阅读程序,写出程序的运行结果 import java.awt.event.ActionEve

70、nt; import java.awt.event.ActionListener;  public class MyMonitor implements ActionListener      public void actionPerformed(ActionEvent e)          Sy stem.out

71、.println("A button has been pressed!");            import java.awt.Frame; import java.awt.Button; import java.awt.BorderLayout;  public class TestActionEvent &#

72、160;    public static void main(String args)    Frame f = new Frame("Test");   Button b = new Button("Press Me!");   MyMonitor mm =

73、0;new MyMonitor();   b.addActionListener(mm);   f.add(b,BorderLayout.CENTER);   f.pack();   f.setVisible(true);        程序运行的用户界面如下图:  当用户鼠标单击”Press Me!”时程序运行结果:_ 16 阅读程序,

74、写出程序的运行结果 import java.io.FileOutputStream; import java.io.DataOutputStream; import java.io.IOException; public class DataOutputDemo       public DataOutputDemo()         

75、  public static void main(String args) throws IOException      FileOutputStream file = new FileOutputStream("invoice.txt");      DataOutputStream out = new

76、 DataOutputStream(file);      String descs = "衬衫", "背包"      double prices = 1159.99, 299.99;      int units = 12, 8; &#

77、160;    for(int i = 0; i < prices.length; i+)       out.writeUTF(descsi);       out.writeChar('t');       out.writeDouble(pricesi

78、);       out.writeChar('t');       out.writeInt(unitsi);       out.writeChar('t');            out.close();  &

79、#160;          import java.io.FileInputStream; import java.io.DataInputStream; import java.io.IOException; import java.io.EOFException; public class DataInputDemo      &#

80、160;public DataInputDemo()                public static void main(String args) throws IOException      DataInputStream in = new DataInp

81、utStream(new FileInputStream("invoice1.txt");   double total = 0;   try     while (true)         String desc = in.readUTF();    &#

82、160;   in.readChar();               double price = in.readDouble();           in.readChar();      int uni

83、t = in.readInt();           in.readChar();            /char chr;           /StringBuffer desc = new&

84、#160;StringBuffer(20);     /while (chr = in.readChar()!= n)      /desc.append(chr);     System.out.println("You've ordered " + unit +  " unit

85、s of "  + desc + " at $" + price);           total = total + unit * price;            

86、;catch (EOFException e)     System.out.println("For a TOTAL of: $" + total);   in.close();              以上程序运行后,屏幕输出结果为:_ 17 阅读以下程

87、序: import    java.io.*; public  class  T estString      public  static  void  m ain(String args )           S 

88、tringC  s = new  S tringC ("hello","java");            System .out.println(s);        class   S tringC  &

89、#160; S tring   s1;   S tring   s2;   S tringC( String  str1 , String  str2 )     s1 = str1;  s2 = str2;   

90、60;public   S tring   toS tring( )    return  s1+s2;    程序运行结果为        hellojava              1

91、8 阅读以下程序: import   java.io.*       public  class  abc                public  static  void   main(String&#

92、160; args )                SubSubClass  x = new  SubSubClass(10 , 20 , 30);              &

93、#160;   x.show();                            class  SuperClass    int  a,b;     

94、     SuperClass(int aa , int  bb)            a=aa;  b=bb;            void  show( )    

95、;        System .out.println("a="+a+"nb="+b);            class   SubClass   extends   SuperClass     

96、0; int c;        SubClass(int  aa,int  bb,int  cc)           super(aa,bb);            c=cc;  &#

97、160;              class   SubSubClass   extends   SubClass       int  a;        SubSubClass(in 

98、t aa,int  bb, int  cc)            super(aa,bb,cc);            a=aa+bb+cc;             

99、;    void  show()           System .out.println("a="+a+"nb="+b+"nc="+c);       程序运行结果为          

100、;   a = 60b = 20falsetruefalsec = 30         19 阅读以下程序 class  T woObjects  public static void main(String args)     B  b1=new  B(); 

101、60;  B  b2=new  B();    System.out.println(b1=b2);    System.out.println(b1!=b2);    System.out.println(b1.equals(b2);     class  B    int  x;

102、60;  B( ) x=1;   程序运行结果为。 In Situation0No Exception caughtIn Situation1in Proc finally20 阅读以下程序 class throwsException      static void Proc(int sel) throws ArithmeticException,ArrayIndexOutO

103、fBoundsException       System.out.println("In Situation"+sel);    if(sel=0)      System.out.println("no Exception caught");      return;  &#

104、160;     else if(sel=1)      int iArray=new int4;      iArray1=3;          public static void main(String args)   &

105、#160;     try       Proc(0);       Proc(1);     catch(ArrayIndexOutOfBoundsException e)       System.out.println("Catch"+e); 

106、    finally       System.out.println("in Proc finally");            程序执行结果: 选择 1. 下列关于JAVA 语言特性的描述中,错误的是_D_。 A支持多线程操作 BJAVA 程序与平台无

107、关  CJAVA 程序可以直接访问Internet 上的对象  D支持单继承与多继承 2. 在下列概念中JAVA语言只保留了_B_。 A运算符重载 B方法重载  C指针  D结构和联合 3. 下列关于JAVA  APPLICA TION 程序在结构上的特点的描述中错误的是_C_。 AJAVA 程序是由一个或多个类组成的。  B组成JAVA 程序的若

108、干个类可以写在一个源代码文件中,也可以分别写在多个源代码文件中。 CJAVA 程序的源代码的文件名要与类名相同。 D组成JAVA 程序的多个类中有且只有一个public class。 4. 下面关于垃圾收集的说法正确的是_C_A一旦一个对象成为垃圾,就立刻被收集掉。 B对象空间被收集掉之后,会执行该对象的finalize 方法。 Cfinalize 方法和C+的析构函数是完全一回事情 D一个对象成为垃圾是因为不再有引用指着它,但是线程并非如此。 5. 以下

109、关于异常的说法正确的是:_D_A一旦出现异常,程序运行就终止了。 B如果一个方法申明将抛出某个异常,它就必须真的抛出那个异常。 C在catch 子句中匹配异常是一种精确匹配。 D可能抛出系统的方法是不需要申明异常的。 6. 在Java 中,一个类可同时定义许多同名的方法,这些方法的形式参数个数、类型或顺序各不相同,传回的值也可以不相同。这种面向对象程序的特性称为_C_。 A、隐藏         B、覆盖  

110、;      C、重载       D、Java 不支持此特性 7. 以下关于构造函数的描述错误的是_A_。 A构造函数的返回类型只能是void 型。 B构造函数是类的一种特殊函数,它的方法名必须与类名相同。 C构造函数的主要作用是完成对类的对象的初始化工作。 D一般在创建新对象时,系统会自动调用构造函数。  8. 在Windows 的命令行窗口下

111、用JAVA 虚拟机运行类名为Hello 的应用程序的正确命令是_C_。 Ajava Hello.class Bjavac Hello Cjavac Hello.class Djava Hello 9. 下列关于容器的描述中,错误的是_D_。 A容器是由若干个组件和容器组成的  B容器是对图形界面中图形元素的一种管理 C容器是一种指定宽和高的矩形范围 D容器都是可以独立的窗口 10. 阅读以下JAVA

112、0;代码, class WhileLoop   _    int i = 1, sum = 0;    while(i<=n)     sum  += i+;    return sum;      public&

113、#160;class T01_WhileLoop       public T01_WhileLoop()             public static void main(String args)       System.out.println(WhileLo

114、op.whileloop(5);        在代码中的划线空白处应填写语句_B_。 Aint whileloop(int n) Bstatic int whileloop(int n) Cvoid whieloop(int n) Dstatic void whileloop(int n) 11. 在下列HTM 文件中调用一个JavaApplet

115、, <HTML> <HEAD> </HEAD> <BODY BGCOLOR=""> <CENTER> <APPLET  co de = "_"  wi dth = "500"  h eight = "300"  &

116、gt; </APPLET> </CENTER> </BODY> </HTML>    若JavaApplet 的源文件如下所示, import java.awt.*; import java.applet.*; public class T02 extends Applet    S tring str;

117、60; public void init()    str = "Here is an Applet."     public void paint(Graphics g)    g.drawString(str, 100, 100 );    在HTM 代码

118、的划线处应填写_。 AT02.java  B  T02.class  C T02  DT02.applet 12. 将以下源程序代码保存在一个JAVA 源代码文件中,正确的文件名应该是_D_。 AWhileLoop.java BT01_WhileLoop.class   CWhileLoop.class D T01_WhileLoop.java 13. 下列界面元素中不是容器的

119、是_A_。 AList  BFrame C Dialog D Panel 14. 下列哪些语句中关于Java 内存回收的说明是正确的是_B_。 A程序员必须创建一个线程来释放内存 B内存回收程序负责释放无用内存 C内存回收程序允许程序员直接释放内存 D内存回收程序可以在指定的时间释放内存对象 15. 设有下面两个赋值语句:          a = Double.parseDouble(“1.2”);          b = Double.valueOf(“1.2”); 下述说法

温馨提示

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

评论

0/150

提交评论