JAVA期末复习题24.docx

上传人:b****1 文档编号:271730 上传时间:2023-04-28 格式:DOCX 页数:23 大小:26.47KB
下载 相关 举报
JAVA期末复习题24.docx_第1页
第1页 / 共23页
JAVA期末复习题24.docx_第2页
第2页 / 共23页
JAVA期末复习题24.docx_第3页
第3页 / 共23页
JAVA期末复习题24.docx_第4页
第4页 / 共23页
JAVA期末复习题24.docx_第5页
第5页 / 共23页
JAVA期末复习题24.docx_第6页
第6页 / 共23页
JAVA期末复习题24.docx_第7页
第7页 / 共23页
JAVA期末复习题24.docx_第8页
第8页 / 共23页
JAVA期末复习题24.docx_第9页
第9页 / 共23页
JAVA期末复习题24.docx_第10页
第10页 / 共23页
JAVA期末复习题24.docx_第11页
第11页 / 共23页
JAVA期末复习题24.docx_第12页
第12页 / 共23页
JAVA期末复习题24.docx_第13页
第13页 / 共23页
JAVA期末复习题24.docx_第14页
第14页 / 共23页
JAVA期末复习题24.docx_第15页
第15页 / 共23页
JAVA期末复习题24.docx_第16页
第16页 / 共23页
JAVA期末复习题24.docx_第17页
第17页 / 共23页
JAVA期末复习题24.docx_第18页
第18页 / 共23页
JAVA期末复习题24.docx_第19页
第19页 / 共23页
JAVA期末复习题24.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

JAVA期末复习题24.docx

《JAVA期末复习题24.docx》由会员分享,可在线阅读,更多相关《JAVA期末复习题24.docx(23页珍藏版)》请在冰点文库上搜索。

JAVA期末复习题24.docx

JAVA期末复习题24

JAVA期末复习题

 填空题  

1. 对象之间可能存在的关系有三种:

_包含_、_继承__和_关联_。

 

2. 面向对象的软件开发过程大体可分为 __面对对象分析、__面对对象设计_和_面对对象测试__三个阶段。

 

3. Java 语言中实现多态的方法有 __继承__、_方法重载_ 和_成员覆盖__。

 

4. Java 语言具有可移植性、高性能、健壮性、安全性和独立于体系结构的__跨平台_特点。

  

5. JAVA语言规定object类是JAVA 程序中所有类的父类,当前类的构造方法用this()表示,直接父类的构造方法用super()表示。

 

6. 如果一个Java  Applet 源程序文件只定义有一个类,该类的类名为MyApplet,则类MyApplet 必须是Applet类的子类并且存储该源程序文件的文件名为   MyApplet.java。

 

7. 如果一个Java  Applet 程序文件中定义有3 个类,则使用Sun 公司的JDK 编译器javac.exe编译该源程序文件将产生 3 个文件名与类名相同而扩展名为.class  的字节码文件。

 

8. 在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用2 字节内存空间,这样,无论是中文字符还是英文字符,都是占用 2字节内存空间。

 

10. Applet 是能够嵌入到HTML 格式的文件中,并能够在浏览器中运行的Java。

 

11. 在Java 中,线程的模型就是一个CPU、程序代码和数据的封装体。

 

12. 键盘键入字符串并在计算机屏幕上显示,这时的数据源是键盘。

 

13. JAVA语言是第一个语言本身就支持线程的编程语言,其对线程的支持主要通过

java.lang.Thread类和java.lang.Runnable接口来实现。

 

14. 设有数组定义:

int   MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70};   则执行以下几个语句后的输出结果是120 。

 

int  s = 0 ; 

for  ( int  i = 0 ; i < MyIntArray.length ; i + + ) 

      if  ( i % 2 = = 1 )    s += MyIntArray[i] ; 

System.out.println( s ); 

15. JVM 是JavaVirtualMachine的缩写; AWT 是abstracwindowtoolkit的缩写。

 

16. 单重继承是指只有一个父类的继承;多重继承是指有一个以上父类的继承;Java 语言出于安全、可靠的考虑,仅支持单重继承;但Java 语言可通过接口来实现多重继承。

 

17. Java 中构成图形用户界面的元素和成分可分为 _容器_、_控制组件_和___用户自定义________________等三类。

 

18. 一个线程的完整生命周期包括如下 5 种状态 _新生_、__就绪_、_运行_、_阻塞_和_死亡_。

 

19. Java 中实现多线程的图径有2 种,一种是__继承thread类__,另一种是_______Runnable接口。

 

20. 任何一个Java 程序都默认引入了一个包,这个包的名字叫java.lang。

 

21. Java 语言中,有一个类是所有类或接口的父类,这个类的名称是object。

  

22. 下列程序的功能是创建了一个显示5 个"Hello!

"的线程并启动运行,请将程序补充完整。

 

public class ThreadTest extends Thread{  

    public static void main(String args[]){  

       ThreadTest t=new _____ThreadTest()_______;  

       t.start();}  

    public void run(){int i=0;  

       while(true){System.out.println("Hello!

");  

          if (i++==4)  break;  

        }  

    } 

23. Java 中访问限定符有public、private_、protected和default 等。

 

24. 事件处理机制中包含以下3 个部分事件源、事件对象和事件监听器,JAVA2 的事件处理模型被称为委托事件处理模型。

 

25. JAVA线程在其生命周期中会处在不同的状态,包括运行、暂停、同步和挂起。

 

26. 图形用户界面由容器和组件组成。

 

27. 表示可直接对数据源进行读写操作的流称为 节点流 。

 

28. 如果要将捕获到的异常在当前方法中处理,应该使用try-catch-final语句来捕获一个或

多个异常。

 

29. 抽象 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。

final方法是不能被当前类的子类重新定义的方法。

 

30. 创建一个名为 MyPackage 的包的语句是   packgeMyPackage  ,该语句应该放在程序的位置

为:

  源代码的第一行              

二、 简答与程序分析题 

1. 简述程序、进程与线程的差别。

 

 2. 简述方法重载与方法覆盖的区别 

方法的覆盖和重载是Java多态性的不同表现。

覆盖是父类与子类之间多态性的一种表现,重载是一个类中多态性的一种表现。

如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被覆盖。

子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被“屏蔽”了。

如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载。

重载的方法是可以改变返回值的类型。

3. 阅读以下程序:

(本题3 分) 

class FatherClass{  

 public FatherClass(){  

  System.out.println("FatherClass Create");  

 }  

}  

public class ChildClass extends FatherClass {  

 public ChildClass(){  

  System.out.println("ChildClass Create");  

 }  

 public static void main(String[] args){  

  FatherClass fc = new FatherClass();  

  ChildClass cc = new ChildClass();  

 }  

}  

程序运行结果是

FatherClassCreate

FatherClassCreate

ChildClassCreate

__________ 

4. 阅读以下程序:

 

class MyThread extends Thread{ 

 public void run(){ 

  System.out.println("MyThread:

 run()"); 

 } 

 public void start(){ 

  System.out.println("MyThread:

 start()"); 

 } } 

class MyRunnable implements Runnable{ 

 public void run(){ 

  System.out.println("MyRunnable:

 run()"); 

 } 

 public void start(){ 

  System.out.println("MyRunnable:

 start()"); 

 } } 

public class MyTest { 

 public static void main(String args[]){ 

  MyThread myThread  =  new MyThread(); 

  MyRunnable myRunnable = new MyRunnable(); 

  Thread thread  =  new Thread(myRunnable); 

  myThread.start(); 

  thread.start(); 

 } } 

此程序的运行结果是___________

MyThread:

start()

MyRunnable:

run()

 5. 阅读程序,写出程序的运行结果 

import java.util.Scanner; 

public class TestThrowException{ 

 public static void main(String[] args){ 

  TestThrowException t = new TestThrowException(); 

  System.out.print("请输入您的年龄:

"); 

  System.out.println("您的年龄:

" + t.inputAge()); 

 }    public int inputAge(){ 

  int result = -1; 

  Scanner scan = new Scanner(System.in); 

  while(true){ 

   try{ 

    result = scan.nextInt(); 

    if(result<0 || result>130){ 

     Exce ption me = new Exception("年龄超出合理范围!

"); 

     throw me;  

    } 

    break;      

   }catch(Exception e1){ 

    Sy stem.out.print(e1.getMessage() + "请重新输入:

"); 

    con tinue; 

   }  

  } 

  return result;  

 } } 

输入 14 5 时 

程序运行结果______________________________________________________ 

6. 阅读以下程序:

 

import java.io.*; 

public class  ReadLineT est{ 

  public static void main(String[ ]  ar gs) throws IOException{ 

   BufferedReader  b=new  BufferedReader (new InputStreamReader(System.in)); 

   String s; 

   System.out.flush(); 

   s=b.readLine(); 

   System.out.println(s); 

  } 

运行以上程序,若从键盘输入:

 Hello< 回车> 

阅读以下程序,输出结果为       Hello          。

 

7. 阅读以下程序    

import    java.io.*; 

public    class   ATest{ 

   public   static   void   m ain(String args[]) { 

   SubClass    sb = new   SubClass( );         

             System .out.println(sb.funOfMod( ));    } 

class    Su perClass{  

  int  a = -10 , b =-3 ;   

class  Sub Class  extends  SuperClass{  

  int  funOfMod( ) {  return   a%b;  }   

 } 

程序运行结果为___________-1_____________ 

8. 阅读以下程序:

 

class  A   

{   public static void main(String[] args)  

{String s,s1=""; 

  char c; 

  s=args[0]; 

  for (int i=0;i

  { c=s.charAt(i); 

   if(c>=' a' && c<='z'){ 

    s1=s1+Character .toUpperCase(c); 

   }else{  s1=s1+Character.toLowerCase(c); } 

  } 

  System.out.println(s1);  } 

若在dos 命令行输入:

java  A   hELLO , 

则输出为         hELLO                      。

 

9. 阅读以下程序:

(本题3 分) 

public  class  C {    public  static  void   m ain(String  ar gs[ ]){   

       int   i , j ; 

   int  a[ ] = { 2,1,4,8,9,5,3}; 

      for  ( i = 0 ; i < a.length-1; i ++ ) { 

       int  k = i; 

       for  ( j = i ; j < a.length ;  j++ ) 

        if  ( a[j]

      int  tem p =a[i]; 

       a[i] = a[k]; 

       a[k] = temp; } 

      for  ( i =0 ; i

       System .out.print(a[i]+"  "); 

        System.out.println( );     } 

}                                    

程序运行结果为        123456789               

 10. 阅读程序,写出程序的运行结果 

public class Person { 

 String name; 

 int age; 

 public String getInfo() { 

       return "Name:

"+ name + "\t" +"age:

"+ age; 

 } }  public class Student extends Person { 

 String school;  

 public String getInfo() { 

       return "Name:

"+ name + "\tAge:

"+ age + "\tSchool:

" + school; 

 } }  

public class Test{ 

 public static void main(String[] args){ 

       Person p = new Person(); 

       p.name = "Tom"; 

       p.age = 18; 

       System.out .println(p.getInfo()); 

        

       S tudent s = new Student(); 

       s.name = "Billy"; 

       s.age = 34; 

       s.school = "THU"; 

       System.out.println( s.getInfo()); 

 } } 

程序运行结果______________________________________________________ 

 11. 阅读程序,写出程序的运行结果 

class Animal{ 

 protected int i = 1;  

}  

class Person extends Animal{ 

 protected int i = 2;  //用于测试同名属性,无现实含义 

 private String name = "Tom"; 

 private int age = 9; 

 public String getInfo(){ 

  return "Name:

" + name + "\tAge:

" + age;  

 }  

 public void testI(){ 

  System.out.println(super.i); 

  System.out.println(i); 

 }  

}  

class Student extends Person{ 

 private int i = 3; 

 private String school = "THU"; 

 public String getInfo(){ 

  return super.getInfo() + "\tSchool:

" + school;  

 }  public void testI(){ 

  System.out.println(super.i); 

  System.out.println(i); 

 }  

}  

public class Test{ 

 public static void main(String args[]){ 

  Person p = new Person(); 

  System.out.println(p.getInfo());  

  p.testI(); 

  Student s = new Student(); 

  System.out.println(s.getInfo()); 

  s.testI();  

 }  

 

程序运行结果______________________________________________________ 

12. 阅读程序,写出程序的运行结果 

interface Runner {  

 public void run(); 

}  interface Swimmer { 

 public void swim(); 

}  

abstract class Animal  {  

 public abstract void eat(); }   

 

class Person extends Animal implements Runner,Swimmer { 

  public void run() { 

   System.out.println("I am running, to the sea!

");   

  } 

  public void swim()  { 

   System.out.println("I am swimming, to the island!

"); 

  } 

  public void eat() { 

   System.out.println("I am eating!

"); 

  } 

}  

public class Test{ 

 public static void main(String args[]){ 

  Test t = new Test(); 

  Person p = new Person(); 

  t.m1(p); 

  t.m2(p); 

  t.m3(p); 

 }  public void m1(Runner f) {  

  f.run();  

 }  public void m2(Swimmer s) { 

  s.swim(); 

 }  public void m3(Animal a) { 

  a.eat(); 

 } } 

程序运行结果______________________________________________________ 

13. 阅读程序,写出程序的运行结果 

public class Person implements Cloneable{ 

 private String name; 

 private int age; 

 public Person(String name,int age){ 

  this.name = name; 

  this.age = age;  

 }  public void setAge(int age){ 

  this.age = age;  

 }  public void setName(String name){ 

  this.name = name;  

 }  

 public void display(){ 

  System.out.println("Name:

" + name + "\tAge:

" + age);  

 } 

 public Object clone(){ 

  Person p = null; 

        try{ 

            p = (Person)super.clone(); 

        }c atch(CloneNotSupportedException e){ 

            e.printStackTrace(); 

        } 

        return p; 

    } 

} public class Book implements Cloneable{ 

 String bookName; 

 double price; 

 Person author; 

 public Book(String bn,double price,Person author){ 

  bookName = bn; 

  this.price = price; 

  this.author = author;  

 }  

 public Object clone(){ 

  Book b = null; 

        try{ 

            b = (Book)super.clone();             

        }c atch(CloneNotSupportedException e){ 

            e.printStackTrace(); 

        } 

        b.author = (Person)author.clone(); 

        return b; 

    } 

 public void display(){ 

  System.out.print(bookName + "\t" + price 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2