当前位置:文档之家› java模拟试卷及答案及解析4

java模拟试卷及答案及解析4

复习题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.Java的字符类型采用的是Unicode编码方案,每个Unicode码占用____个比特位。

( B )A、8B、16C、32D、645.关于下列程序段的输出结果,说法正确的是:( D )public class MyClass{static int i;public static void main(String argv[]){System.out.println(i);}}A、有错误,变量i没有初始化。

B、nullC、1D、06.下列代码的执行结果是:( B )public class Test3{public static void main(String args[]){System.out.print(100%3);. System.out.print(",");System.out.println(100%3.0);}}A、1,1B、1,C、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&&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>C、x<=-3D、x<=0 & x>-39.若要把变量声名为暂时性变量,应使用如下哪种修饰符?( C )A、protectedB、provateC、transientD、volatile10.在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或顺序各不相同,传回的值也可以不相同,这种面向对象程序特性称为:( C )A、隐藏B、覆盖C、重载D、Java不支持此特性11.如要抛出异常,应用下列哪种子句?( B )A、catchB、throwC、tryD、finally12.在使用interface声明一个接口时,只可以使用____修饰符修饰该接口。

( D )A、privateB、protectedC、private protectedD、public13.下列代码的输出结果是:( A )class Parent {void printMe() {System.out.println("parent");}}class Child extends Parent {void printMe() {System.out.println("child");}void printall() {.super.printMe();this.printMe();printMe();}}public class Test_this {public static void main(String args[]) { Child myC=new Child();myC.printall();}}A、parentchildchildB、parentchildparentC、parentchildD、编译错误14.为读取的内容进行处理后再输出,需要使用下列哪种流?( 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、Swing支持图形用户界面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包中定义了多个流类型来实现输入和输出功能,可以从不同的角度对其进行分类,按功能分为:( C )A、输入流和输出流B、字节流和字符流C、节点流和处理流20. 以下程序的运行结果为( B )public class IfTest{public 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 B)Equal C)无输出D)编译出错二.填空题1.java.io包中的_____ObjectinputStream_______和____ ObjectOutputStream_________类主要用于对对象(Object)的读写。

2.在编写异常处理的Java程序中,每个catch语句块都应该与___try____语句块对应,使得用该语句块来启动Java的异常处理机制。

3. 顺序执行以下两个语句的输出结果是:__10__。

String s="我喜欢学习Java!";System.out.println(s.length());4. Java语言通过接口支持_多重___继承,使类继承具有更灵活的扩展性。

5. 实例化对象:就是创建一个对象。

用___new____运算符来实现对象的实例化。

6.我们用____int___来定义一个整数,用__char_____来定义一个字符类型,称为原始数据类型。

7. 当用户在TextField中输入一行文字后,按回车,实现___ActionListner_____接口可实现对事件的响应。

8. 包含Swing构件的Applet(小应用程序)应该是__applet____类的子类。

三、写出下列程序的运行结果1.下列程序的输出结果为:public class TestApple {int i=0;Apple(int i){this.i=i;}Apple increament(){i++;return this;}void print(){System.out.println("i="+i);}public static void main(String[] args) {Apple redapple=new Apple(1000);redapple.increament().increament().print();}1. 结果为:i=10022.下列程序的输出结果为:class SuperClass{private int n;SuperClass(){System.out.println("SuperClass()");SuperClass(int n){System.out.println("SuperClass("+n+")");}}class SubClass extends SuperClass{private int n;SubClass(int n){super();System.out.println("SubClass("+n+")");this.n=n;}SubClass(){super(300);System.out.println("SubClass()");}public class TestSuperSub {public static void main(String args[]){ SubClass sc=new SubClass(400);}}2. 结果为:SuperClass()SubClass(400)3.下列程序的输出结果为:class FatherClass{public int value;public void f(){value=100;System.out.println("FatherClass.value="+value);}}class ChildClass extends FatherClass{public int value;public void f(){super.f();value=200;System.out.println("ChildClass value="+value);System.out.println(value);System.out.println(super.value);}}public class TestInherit {public static void main(String[] args) {ChildClass cc=new ChildClass();cc.f();}}3. 输出结果是:FatherClass.value=100ChildClass value=200200100四、程序设计1.编写一个“Student”类,该类拥有属性:校名、学号、性别、出生日期。

相关主题