1、JAVA复习资料一、 填空题 1对象之间可能存在的关系有三种:_、_和_。 2面向对象的软件开发过程大体可分为_、_和 _三个阶段。 3 Java语言中实现多态的方法有_、_和 _。 4 Java语言具有可移植性、高性能、健壮性、安全性和独立于体系结构的_特点。 5 JAVA语言规定_类是 JAVA程序中所有类的父类,当前类的构造方法用 _表示,直接父类的构造方法用_表示。 6如果一个 Java Applet源程序文件只定义有一个类,该类的类名为 MyApplet,则类 MyApplet必须是 _类的子类并且存储该源程序文件的文件名为 _。 7如果一个 Java Applet程序文件中定义有
2、3个类,则使用 Sun公司的 JDK编译器 _编译该源程序文件将产生 _ 个文件名与类名相同而扩展名为 _的字节码文件。 8在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用_ _字节内存空间,这样,无论是中文字符还是英文字符,都是占用 _字节内存空间。 9 10 Applet是能够嵌入到_ 格式的文件中,并能够在浏览器中运行的 Java。 11在 Java中,线程的模型就是一个 CPU、程序代码和_ 的封装体。12键盘键入字符串并在计算机屏幕上显示,这时的数据源是_。 13 JAVA语言是第一个语言本身就支持线程的编程语言,其对线程的支持主要通过 _类
3、和_来实现。 14设有数组定义:int MyIntArray = 10 , 20 , 30 , 40 , 50 , 60 , 70;则执行以下几个语句后的输出结果是 _ 。 int s = 0 ; for ( int i = 0 ; i MyIntArray.length ; i + + ) if (i%2=1) s+=MyIntArrayi; System.out.println( s ); 15 JVM是_的缩写; AWT是_的缩写。 16单重继承是指_;多重继承是指_;Java语言出于安全、可靠的考虑,仅支持单重继承;但 Java语言可通过_来实现多重继承。 17 Java中构成图形用户
4、界面的元素和成分可分为_、_和 _等三类。 18一个线程的完整生命周期包括如下 5种状态_、_、 _、_和_。 19 Java中实现多线程的图径有 2种,一种是_,另一种是 _。 20任何一个 Java程序都默认引入了一个包,这个包的名字叫_。 21 Java语言中,有一个类是所有类或接口的父类,这个类的名称是_。 22下列程序的功能是创建了一个显示 5个Hello!的线程并启动运行,请将程序补充完整。 public class ThreadTest extends Thread public static void main(String args) ThreadTest t=new _;
5、t.start(); public void run()int i=0; while(true)System.out.println(Hello!); if (i+=4) break; 23 Java中访问限定符有_、_、_和 default等。 24事件处理机制中包含以下 3个部分_、_ _和_,JAVA2的事件处理模型被称为_。 25 JAVA线程在其生命周期中会处在不同的状态,包括 _、_、_和_。 26图形用户界面由_和_组成。 27表示可直接对数据源进行读写操作的流称为 _。 28如果要将捕获到的异常在当前方法中处理,应该使用_语句来捕获一个或29 _方法是一种仅有方法头,没有具体方
6、法体和操作实现的方法,该方法必30创建一个名为 MyPackage 的包的语句是 _,该语句应该放在程序的位置31多个异常。 须在抽象类之中定义。 _方法是不能被当前类的子类重新定义的方法。 为: _ 二、简答与程序分析题 1简述程序、进程与线程的差别。 2简述方法重载与方法覆盖的区别3阅读以下程序: class FatherClass public FatherClass() System.out.println(FatherClass Create); public class ChildClass extends FatherClass public ChildClass() Syste
7、m.out.println(ChildClass Create); public static void main(String args) FatherClass fc = new FatherClass(); ChildClass cc = new ChildClass(); 程序运行结果是_ 4阅读以下程序: class MyThread extends Thread public void run() System.out.println(MyThread: run(); public void start() System.out.println(MyThread: start();
8、 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 thre
9、ad = new Thread(myRunnable); myThread.start(); thread.start(); 此程序的运行结果是_ 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(
10、); public int inputAge() int result = -1; Scanner scan = new Scanner(System.in); while(true) try result = scan.nextInt(); if(result130) Exception me = new Exception(年龄超出合理范围!); throw me; break; catch(Exception e1) System.out.print(e1.getMessage() + 请重新输入: ); continue; return result; 输入 145 时程序运行结果_
11、6阅读以下程序: import java.io.*; public class ReadLineTest public static void main(String args) throws IOException BufferedReader b=new BufferedReader (new InputStreamReader(System.in); String s; System.out.flush(); s=b.readLine(); System.out.println(s); 运行以上程序,若从键盘输入: Hello 阅读以下程序,输出结果为 。 7阅读以下程序 import
12、java.io.*; public class ATest public static void main(String args) SubClass sb = new SubClass( ); System.out.println(sb.funOfMod( ); class SuperClass int a = -10 , b =-3 ; class SubClass extends SuperClass int funOfMod( ) return a%b; 程序运行结果为_ 8阅读以下程序: class A public static void main(String args) Str
13、ing s,s1=; char c; s=args0; for (int i=0;i=a & c=z) s1=s1+Character.toUpperCase(c); else s1=s1+Character.toLowerCase(c); System.out.println(s1); 若在 dos命令行输入:java A hELLO,则输出为 。 9阅读以下程序: public class C public static void main(String args ) int i , j ; int a = 2,1,4,8,9,5,3; for ( i = 0 ; i a.length-1
14、; i + ) int k = i; for ( j = i ; j a.length ; j+ ) if ( ajak ) k = j; int temp =ai; ai = ak; ak = temp; for ( i =0 ; ia.length; i+ ) System.out.print(ai+ ); System.out.println( ); 程序运行结果为 10阅读程序,写出程序的运行结果 public class Person String name; int age; public String getInfo() return Name:+ name + t +age:+
15、 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(); Student s = new Student(); s
16、.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: +
17、 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); publi
18、c 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 clas
19、s 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 publ
20、ic 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; pri
21、vate 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 = (Pers
22、on)super.clone(); catch(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() B
23、ook b = null; try b = (Book)super.clone(); catch(CloneNotSupportedException e) e.printStackTrace(); b.author = (Person)author.clone(); return b; public void display() System.out.print(bookName + t + price + t) ; author.display(); public class TestDeepCopy public static void main(String args) Book b1
24、 = new Book(Java编程,30.50,new Person(张三,34); Book b2 = (Book)b1.clone(); b2.price = 44.0; b2.author.setAge(45); b2.author.setName(李四); b2.bookName = Java开发; b1.display(); b2.display(); 程序运行结果_ 14阅读程序,写出程序的运行结果import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; public class MyAdapt
25、er extends WindowAdapter public void windowClosing(WindowEvent e) System.exit(1); import java.awt.Frame; public class TestAdapter public static void main(String args) Frame f = new Frame(Java Gui); f.setSize(150,150); MyAdapter m = new MyAdapter(); f.addWindowListener(m); f.setVisible(true); 程序运行的用户
26、界面如上图,程序运行效果为_ 15阅读程序,写出程序的运行结果 import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MyMonitor implements ActionListener public void actionPerformed(ActionEvent e) System.out.println(A button has been pressed!); import java.awt.Frame; import java.awt.Button; import java.awt.BorderLayout; public cla