




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、复习题4 一、选择题1.在面对对象的方法中,一个对象恳求另一个对象为其服务的方式是通过发送 ( D )A、调用语句B、命令C、口令D、消息2.Java语言具有很多优点和特点,下列选项中,哪个反映了Java程序并行机制的特点:( B )A、平安性B、多线程C、跨平台D、可移值3.编写和运行Java applet程序与编写和运行Java application程序不同的步骤是 :( B )A、编写源代码B、编写HTML文件调用该小程序,以.html为扩展名存入相同文件夹C、编译过程D、解释执行4.J
2、ava的字符类型接受的是Unicode编码方案,每个Unicode码占用_个比特位。( B )A、8B、16C、32D、645.关于下列程序段的输出结果,说法正确的是 :( D )public class MyClassstatic int i;public static void main(String argv)System.out.println(i);A、有错误,变量i没有初始化。B、nullC、1D、06.下列代码的执行结果是: ( B )public class Test3public sta
3、tic void main(String args)System.out.print(100%3);System.out.print(",");System.out.println(100%3.0);A、1,1B、1,1.0C、1.0,1D、1.0,1.07.下列程序段的输出结果是 :( B )void complicatedexpression_r()int x=20, y=30;boolean b;b=x>50&&y>60|x>50&&y<-60|x<-50&&
4、;y>60|x<-50&&y<-60;System.out.println(b);A、trueB、falseC、1D、08.给出下列代码片段:( D )if(x>0)System.out.println("first");else if(x>-3) System.out.println("second");else System.out.println("third");请问x处于什么范围时将打印字符串“second”?A、x>0B、x>-3C
5、、x<=-3D、x<=0 & x>-39.若要把变量声名为临时性变量,应使用如下哪种修饰符?( C )A、protectedB、provateC、transientD、volatile10.在Java中,一个类可同时定义很多同名的方法,这些方法的形式参数的个数、类型或挨次各不相同,传回的值也可以不相同,这种面对对象程序特性称为 :( C )A、隐蔽B、掩盖C、重载D、Java不支持此特性11.如要抛出特别,应用下列哪种子句? ( B )A、catchB、throwC、
6、tryD、finally12.在使用interface声明一个接口时,只可以使用_修饰符修饰该接口。 ( D )A、privateB、protectedC、private protectedD、public13.下列代码的输出结果是 : ( A )class Parent void printMe() System.out.println("parent"); class Child extends Pare
7、nt void printMe() System.out.println("child"); void printall() super.printMe(); this.printMe(); printMe();
8、 public class Test_this public static void main(String args) Child myC=new Child(); myC.printall(); A、parent child childB、parent child parentC、parent childD、编译错误14.为读取的内容进行处理后再输出,需要使用下列哪种流? (
9、; D )A、File streamB、Pipe streamC、Random streamD、Filter stream15.为实现多线程之间的通信,需要使用下列哪种流才合适?( D )A、Filter streamB、File streamC、Random access streamD、Piped stream16.Swing与aWT的区分不包括 :( D )A、Swing是由纯Java实现的轻量级构件B、Swing没有本地代码C、Swing不依靠操作系统的支持D、S
10、wing支持图形用户界面17.在编写Java applet程序时,若需要对发生大事作出响应和处理,一般需要在程序的开头写上_语句。 ( C )A、import java.awt.*;B、import java.applet.*;C、import java.io.*;D、import java.awt.event.*;18.注释的基本原则不包括 :( D )A、注释应当增加代码的清楚度B、注释要简洁C、在写代码之前写注释D、尽量给每一条语句加注释19.java.io包中
11、定义了多个流类型来实现输入和输出功能,可以从不同的角度对其进行分类,按功能分为:( C )A、输入流和输出流B、字节流和字符流C、节点流和处理流20. 以下程序的运行结果为( B )public class IfTestpublic static void main(String args)int x=3;int y=1;if(x=y)System.out.println("Not equal");elseSystem.out.println("Equal");A)Not equal
12、160; B)Equal C)无输出 D)编译出错 二填空题1.java.io包中的_ObjectinputStream_和_ ObjectOutputStream_类主要用于对对象(Object)的读写。2.在编写特别处理的Java程序中,每个catch语句块都应当与_try_语句块对应,使得用该语句块来启动Java的特别处理机制。3. 挨次执行以下两个语句的输出结果是:_10_。String s="我宠爱学习Java!"System.out.printl
13、n(s.length();4. Java语言通过接口支持_多重_继承,使类继承具有更机敏的扩展性。5. 实例化对象:就是创建一个对象。用_new_运算符来实现对象的实例化。6.我们用_int_来定义一个整数,用_char_来定义一个字符类型,称为原始数据类型。7. 当用户在TextField中输入一行文字后,按回车,实现_ActionListner_接口可实现对大事的响应。8. 包含Swing构件的Applet(小应用程序)应当是_applet_类的子类。三、写出下列程序的运行结果1下列程序的输出结果为:public class TestApple
14、0; int i=0; Apple(int i) this.i=i; Apple increament() i+; return this; void print()
15、0;System.out.println("i="+i); public static void main(String args) Apple redapple=new Apple(1000); redapple.increament().increament().print(); 1. 结果为:i=10022. 下列程序的输出结果为:class
16、 SuperClass private int n; SuperClass() System.out.println("SuperClass()");
17、0; SuperClass(int n) System.out.println("SuperClass("+n+")"); class SubClass extends SuperClass private int n;
18、160; SubClass(int n) super(); System.out.println("SubClass("+n+")");
19、160; this.n=n; SubClass() super(300);
20、0; System.out.println("SubClass()"); public class TestSuperSub public static void main(String args) SubClass sc=new SubClass(400);
21、60; 2. 结果为:SuperClass()SubClass(400) 3. 下列程序的输出结果为:class FatherClass public int value; public void f() value=100;
22、160; System.out.println("FatherClass.value="+value); class ChildClass extends FatherClass public int value; pu
23、blic void f() super.f(); value=200; System.out.println("Child
24、Class value="+value); System.out.println(value); System.out.println(super.value); public class TestInhe
25、rit public static void main(String args) ChildClass cc=new ChildClass(); cc.f();
26、160; 3. 输出结果是:FatherClass.value=100ChildClass value=200200100 四、程序设计1.编写一个“Student”类,该类拥有属性:校名、学号、性别、诞生日期。方法包含设置姓名和成果(setName(),setScore())。 再编写“Student”类的子类:Undergraduate(高校生)。Undergraduate类除拥有父类属性和方法外,还有其自己的属性和方 法:附加属性包括系(department)、专业(major);方法包含设置系别和专业。 (setDepartment(),setMajor()。1.
27、 class Student String name="湖南*学院" int sNum=888888; String sex="男" String birth="1988/08/08" String sname; int Score; void setName(String a) sname=a;
28、 void setScore(int b) Score=b; void show() System.out.println("所在学校:"+name); System.out.println("学号:"+sNum); System.out.println("
29、;性别:"+sex); System.out.println("生日:"+birth); System.out.println("姓名:"+sname); System.out.println("成果:"+Score); class Undergraduate extends Student
30、 String department; String major; void setDeparment(String c) department=c; void setMajo
31、r(String d) major=d; void show1() super.show(); System.out.println("
32、;系部:"+department); System.out.println("专业:"+major); class Student public static void main(String arg) Studen
33、t A=new Student(); Undergraduate B=new Undergraduate(); B.setName("许翼"); B.setScore(95);
34、; B.setDeparment("信息工程系"); B.setMajor("计算机网络"); B.show1(); 2.从键盘或者命令行输入3个数,求这三个数的最大值。2. import javax.swing.JOptionPane;public class MaxNum
35、; public static String sum(int a,int b,int c,int d) if(a>b) d=a;
36、60; if(b>d) d=b; if(c>d)
37、60;d=c; return "你输入的三个数字中,最大的数是"+d; public static void main(String args)
38、60; int number1,number2,number3; try number1=Integer.parseInt(JOptionPane.showInputDialog("Enter the first Number: ");
39、 number2=Integer.parseInt(JOptionPane.showInputDialog("Enter the second Number: "); number3=Integer.parseInt(JOptionPane.showInputDialog("Enter the third Number: "); &
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论