南昌大学JAVA期末复习题.docx

上传人:b****3 文档编号:24807946 上传时间:2023-06-01 格式:DOCX 页数:31 大小:36.80KB
下载 相关 举报
南昌大学JAVA期末复习题.docx_第1页
第1页 / 共31页
南昌大学JAVA期末复习题.docx_第2页
第2页 / 共31页
南昌大学JAVA期末复习题.docx_第3页
第3页 / 共31页
南昌大学JAVA期末复习题.docx_第4页
第4页 / 共31页
南昌大学JAVA期末复习题.docx_第5页
第5页 / 共31页
点击查看更多>>
下载资源
资源描述

南昌大学JAVA期末复习题.docx

《南昌大学JAVA期末复习题.docx》由会员分享,可在线阅读,更多相关《南昌大学JAVA期末复习题.docx(31页珍藏版)》请在冰豆网上搜索。

南昌大学JAVA期末复习题.docx

南昌大学JAVA期末复习题

一、填空题

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

一包含_、—继承—和—关联_。

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

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

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

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

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

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

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

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

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

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

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

通过

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

14.设有数组定义:

intMylntArray[]={10,20,30,40,50,60,70};则

执行以下几个语句后的输出结果是120o

ints=0;

for(inti=0;i

if(i%2==1)s+=MylntArray[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语言中,有一个类是所有类或接口的父类,这个类的名称是。

bjecto

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

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

publicclassThreadiestextendsThread{publicstaticvoidmain(Stringargs[]){

Threadiestt=newThreadTest();

t.start();}

publicvoidrun(){inti=0;

while(true){System.out.println(MHello!

”);

if(i++==4)break;

}

}

23.Java中访问限定符有public、private.、protected禾口default等。

24.事件处理机制中包含以下3个部分事件源、事件对象和事件监听器,

JAVA2的事件处理模型被称为委托事件处理模型。

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

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

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

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

来捕获一个或

多个异常。

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

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

30.创建一个名为MyPackage的包的语句是packgeMyPackage,该语句应

该放在程序的位責

为:

源代码的第一行

二、简答与程序分析题

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

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

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

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

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

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

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

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

3.阅读以下程序:

(本题3分)

classFatherClass{

publicFatherClass(){

System.out.println「FatherClassCreate");

}

}

publicclassChildClassextendsFatherClass{

publicChildClass(){

System.out.println(MChildClassCreate1);

}

publicstaticvoidmain(String[]args){

FatherClassfc=newFatherClass();

ChildClasscc=newChildClassf);

}

}

程序运行结果是

FatherClassCreate

FatherClassCreate

ChildClassCreate4・阅读以下程序:

classMyThreadextendsThread{

publicvoidrun(){

System.out.println("MyThread:

run(门;

}

publicvoidstart(){

System.out.println「MyThread:

start()M);}}

classMyRunnableimplementsRunnable{publicvoidrun(){

System.out.println(MMyRunnable:

run(门;

}

publicvoidstart(){

System.out.println「MyRunnable:

start()M);

}}

publicclassMylest{

publicstaticvoidmain(Stringargs[]){

MyThreadmyThread=newMyThread();

MyRunnablemyRunnable=newMyRunnable();Threadthread=newThread(myRunnable);myThread.start();

thread.start();

}}

此程序的运行结果是

MyThread:

start()

MyRunnable:

run()

5•阅读程序,写岀程序的运行结果

importjava.util.Scanner;

publicclassTestThrowException{

publicstaticvoidmain(String[]args){

TestThrowExceptiont=newTestThrowException();

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

");

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

M+t.inputAge());

}publicintinputAge(){

intresult=-1;

Seannersean=newSeanner(System.in);

while(true){

try{

result=sean.nextlnt();

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

Exceptionme=newException「年龄超出合理围!

J;

throwme;

}

break;

}catch(Exceptione1){

System.out.print(e1

continue;

}

}

returnresult;

}}

输入145时

程序运行结果

6・阅读以下程序:

importjava.io.*;

publicclassReadLineTest{

publicstaticvoidmain(Stri]args)throwslOException{

BufferedReaderb=newBufferedReader(newlnputStreamReader(System.in));

Strings;

System.out.flush();

s=b.readLine();

System,out.println(s);

}

}

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

Hellov回车〉

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

7•阅读以下程序

importjava.io.*;

publicclassATest{

publicstaticvoidmain(Stringargs[]){

SubClasssb=newSubClassf);

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

}

classSuperClass{

inta=-10,b=-3;

}

classSubClassextendsSuperClass{

intfunOfMod(){returna%b;}

}

程序运行结果为-1

8.阅读以下程序:

classA

{publicstaticvoidmain(String[]args)

{Strings,s1=••••;

charc;

s=args[0];

for(inti=0;i

{c=s.charAt(i);

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

s1=s1+Character.tollpperCase(c);

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

}

System.out.println(s1);}

}

若在dos命令行输入:

javaAhELLO,

则输出为hELLOo

9.阅读以下程序:

(本题3分)

publicclassC{publicstaticvoidmain(Stringargs[]){inti,j;

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

for(i=0;i

intk=i;

for(j=i;j

if(a[j]va[k])k=j;

intternp=a[i];

a[i]=a[k];

a[k]=temp;}

for(i=0;i

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

System.out.println();}

}

程序运行结果为123456789

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

publicclassPerson{

Stringname;

intage;

publicStringgetlnfo(){

return"Name:

*1+name+At"+nage:

M+age;

}}publicclassStudentextendsPerson{

Stringschool;

publicStringgetlnfo(){

returnMName:

M+name+AtAge:

'*+age+M\tSchool:

M+school;}}

publicclassTest{

publicstaticvoidmain(String[]args){

Personp=newPerson();

p.name=HbrrT;

p.age=

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

Students=newStudent();s.name="Billy";

s.age=34;

s.school=THU”;

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

}}

程序运

"•阅读程序,写出程序的运行结果

classAnimal{

protectedinti=1;

}

classPersonextendsAnimal{

protectedinti=2;〃用于测试同名属性,无现实含义

privateStringname=

privateintage=9;

publicStringgetlnfo(){

return"Name:

*'+name+,r\tAge:

M+age;

}

publicvoidtestl(){

System.out.println(super.i);

System.out.println(i);

}

}

classStudentextendsPerson{

privateinti=3;

privateStringschool="THU";

publicStringgetlnfo(){

returnsuper.getlnfo()+AtSchool:

'*+school;

}publicvoidtestl(){

System.out.println(super.i);

System.out.println(i);

}

}

publicclassTest{

publicstaticvoidmain(Stringargs[]){

Personp=newPerson();

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

P-testl();

Students=newStudent();

System.out.println(s.getlnfo());s.testl();

}

}

12•阅读程序,写岀程序的运行结果

interfaceRunner{

publicvoidrun();

}interfaceSwimmer{

publicvoidswim();

}

abstractclassAnimal{

publicabstractvoideat();}

classPersonextendsAnimalimplementsRunner,Swimmer{publicvoidrun(){

System.out.println(MIamrunning,tothesea!

J;

}

publicvoidswim(){

System.out.println「lamswimming,totheisland!

M);

}

publicvoideat(){

System.out.println("Iameating!

");

}

}

publicclassTest{

publicstaticvoidmain(Stringargs[]){

Testt=newTest();

Personp=newPerson();

t.m1(p);

t.m2(p);

t.m3(p);

}publicvoidm1(Runnerf){f.run();

}publicvoidm2(Swimmers){s.swim();

}publicvoidm3(Animala){a.eat();

}}

程序运

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

publicclassPersonimplementsCioneable{

privateStringname;

privateintage;

publicPerson(Stringname,intage){

this.name=name;

this.age=age;

}publicvoidsetAge(intage){

this.age=age;

}publicvoidsetName(Stringname){

this.name=name;

}

publicvoiddisplay(){

System.out.println「Name:

**+name+M\tAge:

M+age);}publicObjectcione(){

Personp=null;

try{

p=(Person)super.clone();

}catch(CloneNotSupportedExceptione){

e.printStackTrace();

}

returnp;

}

}publicclassBookimplementsCioneable{

StringbookName;

doubleprice;

Personauthor;

publicBook(Stringbn,doubleprice,Personauthor){bookName=bn;

this.price=price;

this.author=author;

}

publicObjectcione(){

Bookb=null;

try{

b=(Book)super.clone();

}catch(CloneNotSupportedExceptione){e.printStackTrace();

}

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

}

publicvoiddisplay(){

System.out.print(bookName+,r\tM+price+M\tM);author.display();

}}

publicclass7estDeepCopy{

publicstaticvoidmain(Stringargs[]){

Bookb1=newBook(MJava编程",30.50,newPerson(M三”,34));

Bookb2=(Book)b1.clone();b2.price=44.0;b2.author.setAge(45);

b2.author.setName(M四J;

b2.bookName='Java开发:

b1.display!

);

b2.display!

);

}}

运行结

14•阅读程序,写岀程序的运行结果

importjava.awt.event.WindowEvent;

importjava.awt.event.WindowAdapter;

publicclassMyAdapterextendsWindowAdapter{publicvoidwindowClosing(WindowEvente){System.exit

(1);

}}importjava.awt.Frame;

publicclass7estAdapter{

publicstaticvoidmain(Stringargs[]){

Framef=newFrame(MJavaGuiJ;f

MyAdapterm=newMyAdapter();

f.addWindowListener(m);

f.setVisible(true);

}

}

程序运行的用户界面如上图,

程序运行效果为

15•阅读程序,写出程序的运行结果

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

publicclassMyMonitorimplementsActionListener{

publicvoidactionPerformed(ActionEvente){

System.out.println「Abuttonhasbeenpressed!

M);

}

}importjava.awt.Frame;

importjava.awt.Button;

importjava.awt.BorderLayout;

publicclassTestActionEvent{

publicstaticvoidmain(Stringargs[]){

Framef=newFramef^lest*');

Buttonb=newButton("PressMe!

");

MyMonitormm=newMyMonitor();

b.addActionListener(mm);

f.add(b,BorderLayout.CENTER);

f・pack();

f.setVisible(true);

}

}

程序运行的用户界面如下图:

当用户鼠标单击”PressMe!

”时程序运行结果:

16•阅读程序,写出程序的运行结果

importjava.io.FileOutputStream;

importjava.io.DataOutputStream;

importjava.io」0Exception;

publicclassDataOutputDemo{

publicDataOutputDemo(){

}

publicstaticvoidmain(Stringargs[])throw

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

当前位置:首页 > 初中教育 > 中考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1