




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JAVA语言程序设计期末考试模拟试题一、选择题(每小题1分,共 10 分,注:选择答案可能不止一个正确)1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( B )。 A. .java B. .class C. .html D. .exe2、设 x = 1 , y = 2 , z = 3,则表达式 yz/x 的值是( A )。 A. 3 B. 3. 5 C. 4 D. 53、在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( D )方法来完成一些画图操作。 A. start( ) B. stop( ) C. init( ) D. paint( )4、不允许作为类及类成员的访问控制符的是( C )。 A. public B. private C. static D. protected5、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( A )。 A. static void method( ) B. public void method( ) C. final void method( ) D. abstract void method( )6、下面哪些是java语言中的关键字? B A. sizeof B. abstract C. NULL D. Native7、下面语句哪个是正确的? D A. char=abc; B. longl=oxfff; C. floatf=0.23; D. double=0.7E-3;8、以下程序测试String类的各种构造方法,试选出其运行效果。BclassSTRpublic 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 String(chars); String s4=new String(chars,2,5); byte bytes=72,101,108,108,79,33; /A、a和“!”号的ASCII分别为65、97和33 StringBuffer sb=new StringBuffer(s3); sb.append(“!”); String s5=new String(sb); String s6 = new String(bytes); 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 is +s4); System.out.println(The String No.5 is +s5); System.out.println(The String No.6 is +s6); A. TheStringNo.1is B. The String No.1 is TheStringNo.2isString The String No.2 is String 2 TheStringNo.3isastring The String No.3 is a string TheStringNo.4isstring The String No.4 is strin TheStringNo.5isastring The String No.5 is a string!The String No.6 is HELLO! The String No.6 is Hello!C. TheStringNo.1is TheStringNo.2isString2 TheStringNo.3isastring TheStringNo.4isstrin TheStringNo.5isastringThe String No.6 is hello!D以上都不对9、下面语句段的输出结果是( B )inti=9;switch(i) default: System.out.println(default); case0: System.out.println(zero); break; case1: System.out.println(one); case2: System.out.println(two); A. default B. default,zero C. errordefaultclausenotdefined D. nooutputdisplayed10、下面哪些语句能够正确地生成5个空字符串? AB A. Stringa=newString5; B. Stringa=,;for(inti=0;i5;a+=);C. Stringa5; D. String5 a;E. Stringa=newString5;for(inti=0;i5;ai+=null);11、下面哪些选项将是下述程序的输出? ABFGpublicclassOuter publicstaticvoidmain(Stringargs) for(inti=0;i3;i+) for(intj=0;j1)break; System.out.println(j+and+i); A. 0and0 B. 0and1 C. 0and2 D. 0and3 E. 2and2 F. 2and1 G. 2and012、在编写JavaApplication程序时,若需要使用到文件输入输出语句,必须在程序的开头写上(C)语句。A、importjava.awt.*;B、importjava.applet.Applet;C、importjava.io.*;D、importjava.awt.Graphics;二、填空题(每空格1分,共 20 分)1、开发与运行Java程序需要经过的三个主要步骤为 、 和 。2、根据程序的构成和运行环境的不同,Java源程序分为两大类: 和 。3、如果一个Java Applet源程序文件只定义有一个类,该类的类名为MyApplet,则类MyApplet必须是 类的子类并且存储该源程序文件的文件名为 。4、Java源程序是由类定义组成的,每个程序中可以定义若干个类,但是只有一个类是主类。在JavaApplication中,这个主类是指包含 方法的类;在Java Applet里,这个主类是一个系统类 的子类。5、如果一个Java Applet程序文件中定义有3个类,则使用Sun公司的JDK编译器 编译该源程序文件将产生 个文件名与类名相同而扩展名为 的字节码文件。6、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用 字节内存空间,这样无论是中文字符还是英文字符,都是占用 字节内存空间。7、设 x = 2 ,则表达式 ( x + + )3 的值是 。8、若x = 5,y = 10,则x = y的逻辑值分别为 和 。9、 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。 方法是不能被当前类的子类重新定义的方法。10、创建一个名为 MyPackage 的包的语句是 ,该语句应该放在程序的位置为: 。11、设有数组定义: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 );12、在Java程序中,通过类的定义只能实现 重继承,但通过接口的定义可以实现 重继承关系。13、字符串分为两大类,一类是 ,使用 类的对象表示;另一类是 ,使用 类的对象表示。14、创建一个标识有“浙江工业大学”字样的标签对象zjut的语句为 。三、程序填空题。(每空格2分,共 30 分)1、计算 1/1+1/2+1/3+.+1/100 的值。public class Sum public static void main( String args ) double sum = 0.0 ; for ( int i = 1 ; i = 100 ; i + + ) System.out.println( sum=+sum ); 2、从标准输入(即键盘)读入10个整数存入整型数组a中,然后逆序输出这10个整数。 import java.io.* ;public class Reverse public static void main(String args ) int i , n =10 ; int a = new int for ( i = 0 ; i 0;i-) /逆序输出数组a中的元素 System.out.print (ai) System.out.println( ); 3、创建一个标题为按钮的窗框,窗框中显示有按下我字样的按钮。 import java.swing.*;public class abc public static void main(String args) JFrame frame =new FrameOut(); frame.show(); class FrameOut extends JFrame JButton btn; FrameOut(String s) Super ( “按钮”) btn = new Button (“按下我”) setLayout( new Flowlayout()/采用流式布局方式进行布局管理 Container cp = add(but) c setSize(300,200); 4、求两个数的最大值。import java.io.*; public class abc public static void main(String args) MaxClass z = new Maxclass(x,y) System.out.println Z.max() class MaxClass int a,b; MaxClass(int x, int y) A=x B=y int max( ) return(ab)?a:b); 四、写出下面程序的运行结果(每小题10分,共 20 分)1、 import java.io.*;public class abc public static void main(String args ) AB s = new AB(Hello!,I love JAVA.); System.out.println(s.toString( ); class AB String s1; String s2;AB( String str1 , String str2 ) s1 = str1; s2 = str2; public String toString( ) return s1+s2; Hello!I Love AVA 2、 import java.io.* ;public class abc public static void main(String args ) int i , s = 0 ; int a = 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 ; for ( i = 0 ; i a.length ; i + ) if ( ai%3 = = 0 ) s += ai ; System.out.println(s=+s); S=180 3、importjava.io.*;publicclassabcpublicstaticvoidmain(Stringargs)SubSubClassx=newSubSubClass(10,20,30);x.show();classSuperClassinta,b;SuperClass(intaa,intbb)a=aa;b=bb;voidshow()System.out.println(a=+a+nb=+b);classSubClassextendsSuperClassintc;SubClass(intaa,intbb,intcc) super(aa,bb);c=cc;classSubSubClassextendsSubClass inta;SubSubClass(intaa,intbb,intcc)super(aa,bb,cc);a=aa+bb+cc;voidshow() System.out.println(a=+a+nb=+b+nc=+c); A=60 B=20 C=30 4、import javax.swing.*;import java.awt.*;import java.awt.Graphics;public class SimpleGUIFrame extends JFrame public SimpleGUIFrame()final int WIDTH = 400;final int HEIGHT = 300;setSize( WIDTH, HEIGHT );setTitle( Simple GUI Application );Container contentPane = getContentPane();MyPanel onePanel = new MyPanel();contentPane.add(onePanel, BorderLayout.CENTER );JPanel otherPanel = new JPanel();JButton myButton = new JButton( Repaint );otherPanel.add(myButton);contentPane.add(otherPanel, BorderLayout.SOUTH ); public static void main(String args) JFrame appFrame = new SimpleGUIFrame(); appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); appFrame
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年体检行业市场格局与服务质量提升策略研究报告
- 药品运输设备管理制度
- 药品风险沟通管理制度
- 药店培训药品管理制度
- 药店药品库存管理制度
- 设备使用科室管理制度
- 设备备件报废管理制度
- 设备异常运营管理制度
- 设备检修分工管理制度
- 设备相机使用管理制度
- 英语国家概况(修订版)Chapter-18
- 中职语文职业模块1.2《宁夏闽宁镇:昔日干沙滩-今日金沙滩》教案
- 《天文学上的旷世之争》课件
- 2023-2024学年四川省南充市高一下学期7月期末物理试题(解析版)
- 【课件】庆祝新中国成立75周年主题班会课件
- GB/T 44336-2024素肉制品术语与分类
- 人力资源许可证制度(服务流程、服务协议、收费标准、信息发布审查和投诉处理)
- 中学体育七年级《篮球基本技巧》说课课件
- 机械手自动操作控制的程序设计
- 实战-数字化转型工作手册 两份资料
- 请人维修屋顶安全协议书
评论
0/150
提交评论