Java程序设计复习题.doc

上传人:创****公 文档编号:77065373 上传时间:2023-03-13 格式:DOC 页数:9 大小:67.50KB
返回 下载 相关 举报
Java程序设计复习题.doc_第1页
第1页 / 共9页
Java程序设计复习题.doc_第2页
第2页 / 共9页
点击查看更多>>
资源描述

《Java程序设计复习题.doc》由会员分享,可在线阅读,更多相关《Java程序设计复习题.doc(9页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、JavaJava 程序设计复习题程序设计复习题一、选择题一、选择题1下面哪些是 java 语言中的关键字?AsizeofBabstractCNULLDNative2switch 语句中表达式的值必须是A布尔型或字符型B整型或字符型C整型或布尔型D浮点型或整型3以下程序测试 String 类的各种构造方法,试选出其运行效果。class STRpublic static void main(String args)String s1=new String();String s2=new String(String 2);char chars=a,s,t,r,i,n,g;String s3=new

2、String(chars);String s4=new String(chars,2,6);byte bytes=0,1,2,3,4,5,6,7,8,9;StringBuffer sb=new StringBuffer(s3);String s5=new String(sb);System.out.println(The String No.1 is+s1);System.out.println(The String No.2 is+s2);System.out.println(The String No.3 is+s3);System.out.println(The String No.4

3、is+s4);System.out.println(The String No.5 is+s5);AThe String No.1 isThe String No.2 is String 2The String No.3 is a stringThe String No.4 is stringThe String No.5 is a stringBThe String No.1 isThe String No.2 is String 2The String No.3 is a stringThe String No.4 is tringThe String No.5 is a stringCT

4、he String No.1 isThe String No.2 is String 2The String No.3 is a stringThe String No.4 is strinThe String No.5 is a stringD以上都不对4按访问权限从高到低的排列顺序是A友好的,public,protected,private.Bpublic,protected,private,友好的.Cpublic,友好的,protected,private.Dpublic,protected,友好的,private5将一个成员变量声明为常量,应采用的修饰符是:AconstBfinalCp

5、ublicDextends6当编译和运行下列程序段时,会发生什么?class Base class Sub extends Base class Sub2 extends Base public class CExpublic static void main(String argv)Base b=new Base();Sub s=(Sub)b;A通过编译和并正常运行。B编译时出现例外。C编译通过,运行时出现例外。7如果我们在子类中想使用被子类隐藏的父类的成员变量或方法,使用关键字AthisBclassCsuperDsuper class8一个 Java Applet 程序中必须有一个类是A抽

6、象类B接口CWindows 类的子类DApplet 类的子类9对于文本框事件源,可以发生的事件是:AItemEventBChoiceEventCItemChoiceEventDActionEvent10请问所有的例外类皆继承哪一个类?Ajava.io.ExceptionBjava.lang.ThrowableCjava.lang.ExceptionDjava.lang.Error11下面程序段的执行结果是什么?public class Foopublic static void main(String args)tryreturn;finallySystem.out.println(Final

7、ly);A程序正常运行,但不输出任何结果。B程序正常运行,并输出 Finally。C编译能通过,但运行时会出现一个例外。D因为没有 catch 语句块,所以不能通过编译。12编译 JavaApplication 源程序文件产生的字节码文件的扩展名为()。AjavaBclassChtmlDexe13下列哪个是合法的 Java 标识符()?A&2B123.9C_2#Dpublic14对于文本区事件源,可以发生的事件是AItemEventBChoiceEventCTextEventDActionEvent15Button 类创建的一个对象就是一个A多行文本B标签C按钮D文本框16FlowLayout

8、 对应的布局将容器中的组件按照A将容器的空间分为东、西、南、北、中五个区域,中间的区域最大B加入的先后顺序从左向右排列C划分成若干行乘若干列的网格区域,组件就位于这些划分出来的小格中D由用户定制17请问所有的例外类皆继承哪一个类?A java.io.ExceptionBjava.lang.ThrowableC java.lang.ExceptionDjava.lang.Error18List 创建的一个对象就是一个A多行文本B标签C滚动列表D文本框19java.awt 包的 MunuItem 是 Menu 的A子类B父类C没有继承关系D不在同一个包里20类的设计要求它的某个成员变量不能被外部类

9、直接访问,应该使用下面的哪些修饰符获得需要的访问控制()?ApublicBdefaultCprotectedDprivate21MouseEvent 对应的是A键盘事件B窗口事件C按钮事件D鼠标事件22当用Thread(Runnable target)创建线程对象时,创建目标对象的类必须要实现AActionListener接口BThread接口CItemListener接口DRunnable 接口23指出正确的表达式Abyte=128;BBoolean=null;Clong l=0 xfffLDdouble=0.9239d;24获得一个含有本地机的域名和IP地址的对象,可以使用InetAddr

10、ess类的A实例方法getHostName()B静态方法getLocalHost()C实例方法getHostAddress()D静态方法getByName(String s)25运行下列程序,会产生什么结果public class X extends Thread implements Runablepublic void run()System.out.println(this is run();public static void main(String args)Thread t=new Thread(new X();t.start();A第一行会产生编译错误B第六行会产生编译错误C第六

11、行会产生运行错误D程序会运行和启动26要从文件 file.dat文件中读出第10个字节到变量C中,下列哪个方法适合?AFileInputStream in=new FileInputStream(file.dat);in.skip(9);int c=in.read();BFileInputStream in=new FileInputStream(file.dat);in.skip(10);int c=in.read();CFileInputStream in=new FileInputStream(file.dat);int c=in.read();DRandomAccessFile in=

12、new RandomAccessFile(file.dat);in.skip(9);int c=in.readByte();27容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变?ACardLayoutBFlowLayoutCBorderLayoutDGridLayout28给出下面代码:public class Personstatic int arr=new int10;public static void main(String a)System.out.println(arr1);哪个语句是正确的?A编译时将产生错误;B编译时正确,运行时将产生错误;C输出零

13、;D输出空。29哪个关键字可以对对象加互斥锁?AtransientBsynchronizedCserializeDstatic30下列哪些语句关于内存回收的说明是正确的?A程序员必须创建一个线程来释放内存;B内存回收程序负责释放无用内存C内存回收程序允许程序员直接释放内存D内存回收程序可以在指定的时间释放内存对象二、二、填空题填空题1一个Java源程序是由若干个_组成的。2关系运算符的运算结果是_。3类是用来定义对象的_。4局部变量只在定义它的_内有效。5创建一个对象包括_和为对象分配内存两个步骤。6不用private,public,protected 修饰符的成员变量称为_。7如果一个类的声

14、明中没有使用extends 关键字,这个类被系统默认为是_的子类.8多态性就是指父类的某个方法被其_重写时,可以各自产生自己的功能行为.。9给定下面的未完成的代码片断:public class Exampleint x,y;public Example(int a)x=a;public Example(int a,int b)/和上面一个参数的构造方法做同样的操作,包括赋值x=a y=b;如果要用最简捷的一行代码实现/和上面一个参数的注释所指出的功能,请写出你认为最合适的一行代码:10如果有一个类MyFrame是Frame的子类,能够被不同包中的类所使用,同时又能够为线程提供运行代码(run(

15、)方法),请写出该类的声明头。你的解答:_11分析下面一段程序:class Aclassvoid go()System.out.println(Aclass);public class Bclass extends Aclassvoid go()System.out.println(Bclass);public static void main(String args)Aclass a=new Aclass();Aclass a1=new Bclass();a.go();a1.go();程序运行结果是:_12指出下列程序的运行结果public class A1public static voi

16、d main(String args)int i=9;switch(i)default:System.out.println(default);case 0:System.out.println(zero);break;case 1:System.out.println(one);case 2:System.out.println(two);程序运行结果是:_13下面程序段的执行结果是什么?public class Foopublic static void main(String args)tryreturn;finallySystem.out.println(Finally);程序运行结果

17、是:_14指出下列程序运行的结果class Outer1private int a;void foo(double d,final float f)String s;final boolean b;class Innervoid methodInner()System.out.println(in the Inner);public static void main(String args)Outer1 me=new Outer1();me.foo(123,123);System.out.println(outer);程序运行结果是:_15下列代码哪几行会出错:_public class Mo

18、difypublic static void main(String args)int I,j,k;I=100;while(I0)j=I*2;System.out.println(The value of j is +j);k=k+1;I-;16请写出下面程序的运行结果。class Tomint x=98,y;void f()int x=3;y=x;System.out.println(y);public static void main(String args)Tom t1=new Tom();t1.f();结果:_17给定下面的未完成的代码片断:public class Examplein

19、t x,y;public Example(int a)x=a;public Example(int a,int b)/和上面一个参数的构造方法做同样的操作,包括赋值 x=ay=b;如果要用最简捷的一行代码实现/和上面一个参数的注释所指出的功能,请写出你认为最合适的一行代码:_18下列程序中构造了一个 SET 并且调用其方法 add(),输出结果是_public class Apublic int hashCode()return 1;public Boolean equals(Object b)return truepublic static void main(String args)Set

20、 set=new HashSet();set.add(new A();set.add(new A();set.add(new A();System.out.println(set.size();19下列程序的运行结果是_class Aclass Dogprivate String name;private int age;public int step;Dog(String s,int a)name=s;age=a;step=0;public void run(Dog fast)fast.step+;public static void main(String args)A a=new A()

21、;Dog d=a.new Dog(Tom,3);d.step=25;d.run(d);System.out.println(d.step);三阅读程序回答问题三阅读程序回答问题1class Person private int age;public void setAge(int i)if(i130)return;age=i;public int getAge()return age;public class TestPerson public static void main(String args)Person p1=new Person();p1.setAge(3);p1.setAge(

22、-6);System.out.println(p1.getAge();(1)说明 age 的访问权限(2)请在画线处填上方法的访问权限(3)方法 setAge 中对 age 赋值对吗?为什么?(4)能否在 main()方法中添加 p1.age=3;语句?(5)方法 setAge 和 getAge 的作用是什么?2在空白处填上合适的语句。public class ServerTimedOutException extends Exception private int port;public ServerTimedOutException(String message,int port)supe

23、r(message);this.port=port;public int getPort()return port;class Client/在下行空白出填上声明抛弃 ServerTimedOutException 例外的语句public void connectMe(String serverName)_int success;int portToConnect=80;success=open(serverName,portToConnect);if(success=-1)/*在下行空白处填上抛出 ServerTimedOutException 例外的语句*/_3、class Tom pro

24、tected float weight;protected float f(float a,float b)class Jerry void g()Tom cat=new Tom();cat.weight=23f;/合法.cat.f(3,4);/合法.假如 Jerry 与 Tom 是同一个包中的类,Jerry 类中的划线语句是否合法?请说明理由。四根据要求编写程序四根据要求编写程序1编写一个程序,用选择法对数组 a=20,10,50,40,30,70,60,80,90,100进行从大到小的排序。2编写一个应用程序,创建三个线程分别显示各自的时间。3编写一个计算器程序,只有加减乘除功能,当作 applet 运行。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 管理文献 > 事务文书

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com