java期末考试题 ()

别妄想泡我
623次浏览
2020年08月03日 01:44
最佳经验
本文由作者推荐

捐赠仪式上的讲话-南京政治学院分数线


一、选择题(每道题只有一个正确答案,每小题2分,共30分)15道题
1、关于Java语言叙述错误的是:( C)
A.Java语言具有跨平台性
B.Java是一种面向对象的语言
C.Java语言中的类可以多继承
D.Java的垃圾收集机制自动回收程序已不再使用的对象
2、以下叙述正确的是:( B)的确台a
A.构造方法必须是public方法
B.main方法必须是public方法
C.Java应用程序的文件名可以是任意的
D.构造方法应该声明为void类型
3、关于Java中数据类型叙述正确的是:( B)
A、整型数据在不同平台下长度不同
B.boolean类型数据只有2个值,true和false
C.数组属于简单数据类型
D.Java中的指针类型和C语言的一样
4、设 int x=1,float y=2,则表达式 x y的值是:( D)
A.0
B.1
C.2
D.以上都不是
5、以下语句有语法错的是:( A)
A.int x=1;y=2;z=3
B.for (int x=10,y=0;x>0;x++);
C.while (x>5);
D.for(; );
6、关于类和对象的叙述正确的是:( A)
A.Java的类分为两大部分:系统定义的类和用户自定义的类


B.类的静态属性和全局变量的概念完全一样,只是表达形式不同
C.类的成员至少有一个属性和一个方法
D.类是对象的实例化
7、以下有关构造方法的说法,正确的是:( A)
A.一个类的构造方法可以有多个
B.构造方法在类定义时被调用
C.构造方法只能由对象中的其它方法调用
D.构造方法可以和类同名,也可以和类名不同
8、以下有关类的继承的叙述中,正确的是:( D)
A.子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属

B.子类只能继承父类的方法,不能继承父类的属性
C.子类只能继承父类的非私有属性,不能继承父类的方法
D.子类不能继承父类的私有属性
9、下列属于容器的组件有:( B)
A.JButton
B.JPane
C.Canvas
D.JTextArea
10、void的含义:( C)
A.方法体为空
B.定义的方法没有形参
C.定义的方法没有返回值
D.方法的返回值不能参加算术运算
11、关于Java中异常的叙述正确的是:( D)
A.异常是程序编写过程中代码的语法错误
B.异常是程序编写过程中代码的逻辑错误
C.异常出现后程序的运行马上中止


D.异常是可以捕获和处理的
12、所有的异常类皆继承哪一个类?( C)
A.
B.
C.
D.
13、下面哪个不是java语言中的关键字?( B)
A.long
B.sizeof
C.instanceof
D.const
14、为实现进程之间的通信,需要使用下列那种流才合适?(D)
A.Data stream
B.File stream
C.Buffered stream
D.Piped stream
15、在复选框中移动鼠标,然后单击一选项,要捕获所选项必需实现哪个接口?
(D)
A.ActionListener
B.MouseListener
C.MouseMotionListern
D.ItemListener
二、填空题(每空1分,共20分)
1、面向对象程序设计所具有的基本特征是:___抽象 性___,_封装性___,_继承
性__,_多态性__
2、数组x定义如下
int x[ ][ ]=new int[3][2]
则 x..length的值为____3________,


x[0].length的值为_____2_______。
3、Java中实现多线程一般使用两 种方法,一是___继承Thread类_________,
二是_____实现Runnable方 法__________
4、Java的图形用户界面设计中,有很多布局管理器用来摆放组件的位置 ,一般
用到的布局管理器有(列出四种即可)__FlowLayout_____,___GridL ayout_____,
__BorderLayout_____,___CardLayout__ _____
5、Applet常用的方法是:__init()_、__run()__、__sto p()__和destroy()。
三、阅读程序,写出程序的输出结果(每题5分,共20分)
1、class A{
private int privateVar;
A(int _privateVar){
privateVar=_privateVar;
}
boolean isEqualTo(A anotherA){
if ==
return true;
else
return false;
}
}
public class B{
public static void main(String args[]){
A a = new A(1);
A b = new A(2);

}
}
程序的输出结果为:____false_____


2、class A {
double f(double x, double y) {
return x * y;
}
}
class B extends A {
double f(double x, double y) {
return x + y;
}
}
public class Test {
public static void main(String args[]) {
B obj = new B();

}
}
程序的输出结果为:__ The program output is 10_
3、public class Unchecked {
public static void main(String[] args) {
try {
method();
} catch (Exception e) {

} finally {

}
}
static void method() {


try {
wrench();

} catch (ArithmeticException e) {

} finally {

}

}
static void wrench() {
throw new NullPointerException();
}
}
程序的输出结果为:
E
A
B
4、public class Test {
public static void main(String[] args) {
int x;
int a[] = { 0, 0, 0, 0, 0, 0 };
calculate(a, a[5]);


}

static int calculate(int x[], int y) {


for (int i = 1; i < i++)
if (y <
x[i] = x[i - 1] + 1;
return x[0];
}
}
程序的输出结果为:
the value of a[0] is 0
the value is a[5] is 5
一、单选择题(每小题2分,共10分)
1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文
件的扩展名为( )。
A..java B. .class
C..html D. .exe
2、设 x = 1 , y = 2 , z = 3,则表达式 y+=z--++x 的值是( )。
A. 3 B. 3. 5
C. 4 D. 5
3、在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( )
方法来完成一些画图操作。
A. start( ) B. stop( )
C. init( ) D. paint( )
4、不允许作为类及类成员的访问控制符的是( )。
A. public B. private
C. static D. protected
5、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使 用类
名AB作为前缀就可以调用它,该方法头的形式为( )。
A. static void method( ) B. public void
method( )
C. final void method( ) D. abstract void
method( )

二、填空题(每空格1分,共20分)
1、开发与运行Java程序需要经过的三个主要步骤
为 、

和 。
2、如果一个Java Applet源程序文件只定义有一个类,该类的类名为MyApple t,
则类MyApplet必须是 类的子类并且存储该源程序
文件的文件名为 。


3、如果一个Java Applet程序文件中定义有3个类,则使用Sun公司的JDK编

器 编译该源程序文件将产生 个文件名
与类名相同而扩展名为 的字节码文件。
4、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码

用 字节内存空间,这样,无论是中文字符还是英文字符,都是

用 字节内存空间。
5、设 x = 2 ,则表达式 ( x + + )/3 的值是 。
6、若x = 5,y = 10,则x < y和x >= y的逻辑值分别为 和 。
7、 方法是一种仅有方法头,没有具体方法体和操作实现的方法,
该方法必须在抽象类之中定义。 方法是不能被当前类的子类重新定
义的方法。
8、创建一个名为 MyPackage 的包的语句
是 ,
该语句应该放在程序的位置
为: 。
9、设有数组定义:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执
行以下几个语句后的输出结果是 。
int s = 0
for ( int i = 0 ; i < i + + )
if ( i % 2 = = 1 ) s += MyIntArray[i]
s );
10、在Java程序中,通过类的定义只能实现 重继承,但通过接口的
定义可以实现 重继承关系。

三、写出下列程序完成的功能。(每小题5分,共20分)

1、public class Sum
{ public static void main( String args[ ])
{ double sum =
for ( int i = 1 i <= 100 i + + )
sum += (double) i

}
}

2、 import .*
public class Reverse
{ public static void main(String args[ ])
{ int i , n =10
int a[ ] = new int[10];
for ( i = 0 i < n i ++ )


try {
BufferedReader br = new BufferedReader(
new InputStreamReader);
a[i] = ( ));
public class abc
{ public static void main(String args[])
{ new FrameOut(); }
}
class FrameOut extends Frame
public class abc
{ public static void main(String args[])
{ SubClass sb = new SubClass( );
));
}
}
class SuperClass
{ int a = 10 , b = 20 }
class SubClass extends SuperClass
{ int max( ) { return ((a>b)?a:b); } }

四、写出下面程序的运行结果(每小题10分,共30分)
1、 import .*;
public class abc
{ public static void main(String args[ ])
{ AB s = new AB(VA.
));
}
}
class AB {
String s1;
String s2;
AB( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}

2、 import .*
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 < i ++ )


if ( a[i]%3 = = 0 ) s += a[i]

}
}

3、import .* ;
public class abc
{
public static void main(String args[ ])
)
{ }
}
class SubClass extends SuperClass
{ int c;
SubClass(int aa,int bb,int cc)
{ super(aa,bb);
c=cc;
}
}
class SubSubClass extends SubClass
{ int a;
SubSubClass(int aa,int bb,int cc)
{ super(aa,bb,cc);
a=aa+bb+cc;
}
void show()
{ }
}

五、使用Java语言编写程序。(每小题10分,共20分)

1、编写一个字符界面的Java Application 程序,接受用户输入的10个整数,
并输出这10个整数的最大值和最小值。

2、编写一个完整的Java Applet 程序使用复数类Complex验证两个复数 1+2i
和3+4i 相加产生一个新的复数 4+6i 。
复数类Complex必须满足如下要求:
(1) 复数类Complex 的属性有:
RealPart : int型,代表复数的实数部分
ImaginPart : int型,代表复数的虚数部分
(2) 复数类Complex 的方法有:
Complex( ) : 构造函数,将复数的实部和虚部都置0
Complex( int r , int i ) : 构造函数,形参 r 为实部的初值,i为虚部的初
值。


Complex complexAdd(Complex a) : 将当前复数对象与形参复数对象相
加,所得的结果仍是一个复数值,返回给此方法的调用者。
String ToString( ) : 把当前复数对象的实部、虚部组合成 a+bi 的字符串
形式,其中a 和 b分别为实部和虚部的数据。


《JAVA语言程序设计》期末考试模拟试题
参考答案及评分标准

一、单选择题(每小题2分,共10分)
1、B 2、A 3、D 4、C 5、A

二、填空题(每空格1分,共20分)
1、编辑源程序、编译生成字节码、解释运行字节码
2、Applet、MyApplet
3、、3、 . class
4、2 、2
5、0
6、true 、 false
7、抽象(abstract)方法、最终(final)方法
8、package MyPackage 应该在程序第一句。
9、120
10、单、多

三、写出下列程序完成的功能。(每小题5分,共20分)
1、计算 11+12+13+...+1100 的值。
2、从标准输入(即键盘)读入10个整数存入整型数组a中,然后逆序输出这10
个整数。
3、创建一个标题为按钮的窗框,窗框中显示有按下我字样的按钮。
4、求两个数的最大值。

四、写出下面程序的运行结果(每小题10分,共30分)
1、Hello! I love JAVA.
2、s = 180
3、a=60
b=20
c=30

五、使用Java语言编写程序。(每小题10分,共20分)
1、参考程序如下:
import .*
public class abc
{
public static void main(String args[ ])


{ int i , n = 10 , max = 0 , min = 0 , temp = 0;
try {
BufferedReader br = new BufferedReader(
new InputStreamReader);
max = min = ( ));
} catch ( IOException e ) { }
for ( i = 2 i <= n i ++ ) {
try {
BufferedReader br = new BufferedReader(
new InputStreamReader);
temp = ( ));
if (temp > max ) max=temp;
if (temp < min) min=temp;
} catch ( IOException e ) { }
}

}
}

2、参考程序如下:
import .*
import .*
public class abc extends Applet
{
Complex a,b,c
public void init( )
{
a = new Complex(1,2);
b = new Complex(3,4);
c = new Complex();
}

public void paint(Graphics g)
{
c=(b);
(第一个复数:
(第二个复数:
(两复数之和:
}
}

class Complex
{
int RealPart lass”后缀的字节码文件。(Y)


3、Java Applet是由独立的解释器程序来运行的。(N)
4、Java Application是由独立的解释器程序来运行的。(Y)
5、Java Applet的字节码文件必须嵌入HTML的文件中并由负责解释HTML
文 件的WWW浏览器充当解释器来解释运行。(Y)
7、Java源程序是由类定义组成的,每个程序可 以定义若干个类,但只有
一个类是主类。(Y)
8、Java中数组的元素只能是简单数据类型的量。(N)
9、Vector类中的对象不能是简单数据类型。(Y)
10、Java的String类的对象既可以是字符串常量,也可以是字符串变量。
(N)
11、Java中用户自定义的图形界面元素也可以响应用户的动作,具有交互
功能。(N)
12、Java的屏幕坐标是以像素为单位,容器的左上角被确定为坐标的起点。
(Y)
13、在Java中,并非每个事件类都只对应一个事件。(Y)
14、一个类只能有一个父类,但一个接口可以有一个以上的父接口。(Y)
15、由继承性可知,程序中子类拥有的成员数目一定大于等于父类拥有的
成员数目。(N)
16、Java语言中的数组元素下标总是从0开始,下标可以是整数或整型表
达式。(N)
17、注释的作用是使程序在执行时在屏幕上显示class StaticStuff
2. {
3. static int x=15;
4. static {x*=3;}
5. public static void main(String args[])
6. {
7. }
9. static {x=3;}
}
(A) 4行与9行不能通过编译,因为缺少方法名和返回类型
(B) 9行不能通过编译,因为只能有一个静态初始化器
(C) 编译通过,执行结果为:x=15
(D) 编译通过,执行结果为:x=3
14、关于以下程序代码的说明正确的是( C)
1. class HasStatic{


2. private static int x = 100;
3. public static void main(String args[]){
4. HasStatic hs1 = new HasStatic();
5. ++;
6. HasStatic hs2 = new HasStatic();
7. ++;
8. hs1=new HasStatic();
9. ++;
10. = ”+x);
11. }
12. }
(A) 5行不能通过编译,因为引用了私有静态变量
(B) 10行不能通过编译,因为x是私有静态变量
(C) 程序通过编译,输出结果为: x=103
(D) 程序通过编译,输出结果为:x=100
15、以下选项中循环结构合法的是( C)
(A) while(int i<7){
i++;
is ”+i);
}
(B) int j=3;
while(j){
j is ”+j);
}
(C) int j=0;
for(int k=0;j+k!=10;j++,k++){
is ”+j+ “ k is ”+k );
}
(D) int j=0;
do{
is ”+j++);
if (j==3){continue loop;}
}while(j<10);
16、类Text1定义如下:(B)


public class Test1{
public float aMethod(Float a, float b){}
***
}
将以下哪种方法插入行 *** 是不合法的。( )
(A) public float aMethod(float a,float b,float c){}
(B) public float aMethod(float c,float d){}
(C) public int aMethod(int a,int b){}
(D) public float aMethod(int a,int b,int c){}
17、创建字符串s: s=new String(“xyzy”);以下哪条语句将改变s( D)
(A) (“a”) (B) (s)
(C) (3) (D) 以上语句都不会
18、关于以下程序段,正确的说法是( B)
String s1 = “ac”+ “def”;
Strimg s2 = new String(s1);
if(s2))
succeeded”);
(A) 行4与行6都将执行 (B)行44执行,行6不执行
(C) 行6执行,行4不执行 (D) 行4、行6都不执行
19、关于以下代码段的说法正确的是(D )
String s = “abcde”;
StringBuffer s1 = new StringBuffer(“abcde”);
if(s1))
s1 = null;
if(s))
s=null;
(A) 第1行编译错误,String的构造器必须明确调用
(B) 第3行编译错误,因为s1与s2有不同的类型
(C) 编译成功,但执行时在第5行有异常抛出
(D) 编译成功,执行过程中也没有异常抛出
20、以下说法哪项是正确的( A)
class MyListener extends MouseAdapter implements MouseListener{
public void mouseEnter(MouseEvent mev){


entered.”);
}
}
(A) 以上代码可通过编译
(B) 不能通过编译,因为没有实现MouseListener接口中的所有方法
(C) 不能通过编译,因为类头定义不能分行
(D) 能通过编译,若组件用该类作为Mouse的监听者并且接收了
mouse- exited事件,则在执行过程中会抛出异常
21、关于以下程序段的说法,正确的是( A)
1. class MyListener implements
2. ActionListener,ItemListener{
3. public void actionPerformed(ActionEvent ae){
4. public void itemStateChanged(ItemEvent ie){
6. }
8. }
(A) 可通过编译
(B) 第2行产生编译错误
(C) 第3行产生编译错误
(D) 第5行产生编译错误
22、通过调用new JList(10,false)创建一个列表,关于该列表的几个说法
哪项是错误的。( D)
(A) 该列表不支持复选
(B) 该列表一次可显示10个选项
(C) 根据需要该列表可能有垂直滚动条
(D) 该列表有10个选项
23、以下哪项可能包含菜单条( B)
(A) JPanel (B) JFrame (C) Applet (D) JDialog
24、以下代码完成画线功能,指出所画线的颜色( C)
1. (0,0,100,100);
(A) red (B) green (C) yellow (D) cyan
25、关于以下代码所画图形的说明,正确的是( B)
1.;
2. (10,10,10,50);
3.


4. (100,100,150,150);
(A) 一条40像素长的垂直红线,一个边长为150像素的红色四方形
(B) 一条40像素长的垂直黑线,一个边长为150像素的红色四方形
(C) 一条40像素长的垂直黑线,一个边长为150像素的红色四方形
(D) 一条40像素长的垂直红线,一个边长为150像素的红色四方形
一、 程序阅读
1、阅读以下程序,输出结果为 。(21)
class D{
public static void main(String args[])
int d=21;
Dec dec=new Dec( );
(d);
Dec{
public void decrement(int decMe){
decMe = decMe - 1;
}
}
2、以下程序的输出结果为 。(结果为: Boy)
public class Short{
public static void main(String args[ ]) {
StringBuffer s = new StringBuffer(“Boy”);
if(( )<3)&& (“男孩”) . equals(“False”)))
;
结果为: ”+s);
}
}
3、以下程序段的输出结果为 。(Message four)
int x=0,y=4, z=5;
if ( x>2){
if (y<5){
one”);
}
else {


two”);
}
}
else if(z>5){
three”);
}
else {
four”);
}
4、以下程序段的输出结果为 。.)
int j=2;
switch ( j ) {
case 2:
2+1 :

default:
is “+j);
break;
}
5、以下程序段的输出结果为 。(int)
class Cruncher{
void crunch( int i ){
crunch(String s){
static void main(String args[ ]){
Cruncher crun=new Cruncher ( );
char ch=’p’;
(ch);
}
}
6、阅读以下程序,写出输出结果 。(99)
class Q6{
public static void main(String args[ ]){
Holder h=new Holder( );


=100;
(h);
}
}
class Holder{
public int held;
public void bump(Holder theHolder){
- -;
}
}
7、阅读以下程序,请写出输出结果 。(true)
public class EqualsMethod {
public static void main(String[] args) {
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
1、 application中的主类需包含main方法,main方法的返回类型是什么?
( D )
A、int B、float C、double D、void
2、 有以下方法的定义,请选择该方法的返回类型( D )。
ReturnType method(byte x, double y)
{
return (short)xy*2;
}
A、byte B、short C、int D、double
3、 在编写Java Applet程序时,若需要对发生的事件作出响应和处理,一般需
要在程序的开头写上( D )语句。
A、import .* B、import .*
C、import .* D、import
4、 容器Panel和Applet缺省使用的布局编辑策略是( A )
A、BorderLayout B、FlowLayout C、GridLayout D、CardLayout
5、 以下哪个不是Java的关键字?( A )
A、TRUE B、const C、super D、void
6、 有程序如下,关于程序的描述哪个是正确的?( A )
public class Person{
i. static int a[] = new int[10];
ii. public static void main(String a[])
iii. { }


}

A、编译将产生错误

C、正确,输出0
B、编译时正确,但运行时将产生错误
D、正确,输出?null
7、 以下关于构造函数的描述错误的是( A )。
A、构造函数的返回类型只能是void型。
B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。
C、构造函数的主要作用是完成对类的对象的初始化工作。
D、一般在创建新对象时,系统会自动调用构造函数。
8、 有语句String s=”hello world”; ,以下操作哪个是不合法的?( )
A、int i=(); B、s>>>=3; C、String ts=(); D、String t=s+”!”;
9、 有程序片段如下,以下哪个表示式的结果为true?( A )
Float s=new Float;
Float t=new Float;
Double u=new Double;
A、s==t B、(t) C、(s) D、(u)
10、 欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是
正确的 ?(B)
A、ArrayList myList=new Object()
B、List myList=new ArrayList()
C、ArrayList myList=new List()
D、List myList=new List();
11、 paint()方法使用哪种类型的参数? (A)
A、Graphics B、Graphics2D C、String D、Color
12、 指出正确的表达式 (C)
A、 byte=128; B、Boolean=null; C、 long l=0xfffL; D、 double=;
13、 指出下列程序运行的结果 (B)
public class Example{
String str=new String(
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
,;


}


public void change(String str,char ch[]){
str=
ch[0]='g';
}
}
A、 good and abc B、good and gbc C、 test ok and abc D、test ok and
gbc
14、 运行下列程序, 会产生什么结果 (A)
public class X extends Thread implements Runable{
public void run(){

}
public static void main(String args[])
{
Thread t=new Thread(new X());
();
}
}
A、 第一行会产生编译错误 B、 第六行会产生编译错误
C、 第六行会产生运行错误 D、 程序会运行和启动
15、 要从文件文件中读出第10个字节到变量C中,下列哪个方法适合? (B)
A、FileInputStream in=new FileInputStream(
B、FileInputStream in=new FileInputStream(
C、FileInputStream in=new FileInputStream(
D、RandomAccessFile in=new RandomAccessFile(
16、 容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器
大小的变化而改变? (B)
CardLayout
FlowLayout
BorderLayout
GridLayout
17、 给出下面代码: (C)
public class Person{
static int arr[] = new int[10];
public static void main(String a[])
{



}
}

那个语句是正确的?
A、 编译时将产生错误; B、编译时正确,运行时将产生错误;
C、 输出零; D、输出空。
18、 下列哪些语句关于内存回收的说明是正确的? (B)
A、 程序员必须创建一个线程来释放内存;
B、 内存回收程序负责释放无用内存
C、 内存回收程序允许程序员直接释放内存
D、 内存回收程序可以在指定的时间释放内存对象
19、 下列代码哪几行会出错: (C)
1) public void modify() {
2) int I, j, k;
3) I = 100;
4) while ( I > 0 ) {
5) j = I * 2;
6) (
7) k = k + 1;
8) I--;
9) }
10) }
A、 line 4 B、 line 6 C、 line 7 D、
一、 程序阅读
1、 阅读以下程序:
class Exp1
{
public static void main(String[] args)
{
String s,s1=
char c;
s=args[0];
for (int i=0;i<();i++)
{ c=(i);
if(c>='a' && c<='z'){
s1=s1+(c);
}else{
s1=s1+(c); }
line 8


}
}
}
若在dos命令行输入:java Exp1 cHINA,则输出为
China 。
2、 阅读以下程序:
import .*;
public class AboutFile{
public static void main(String[ ] args)throws IOException{
BufferedReader b=new BufferedReader (new InputStreamReader);
String s;
s=();
is:”+s);
}
}
运行以上程序,若从键盘输入:
java<回车>
则输出结果为 String is: java 。
3、 以下程序段的输出结果为 。
public class C
{
public static void main(String args[ ]){
int i , j
int a[ ] = { 5,1,3,9,7};
for ( i = 0 i < i ++ ) {
int k = i;
for ( j = i j < j++ )
if ( a[j] int temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for ( i =0 i<; i++ )

);
}
}
4、 阅读以下程序,写出输出结果 Animal Cat 。
class Animal {
Animal() {
( }
}
public class Cat extends Animal {
Cat() {
( }

public static void main(String[] args) {
Cat kitty= new Cat(); }
}


5、 阅读以下程序,输出结果为 1 。
import .*;
public class ATest{
public static void main(String args[]) {
SubClass sb = new SubClass( );
)); }
}
class SuperClass{
int a = 10 , b = -3
}
class SubClass extends SuperClass{
int funOfMod( ) { return a%b; }
}
6、 以下程序段的输出结果为 int, int 。
class Cruncher{
void crunch( int i ){
}
void crunch(String s){
}
public static void main(String args[ ]){
Cruncher crun=new Cruncher ( );
char ch=’h’;
int i=12;
(ch);;
public class TestString
{ public static void main(String args[ ])
{ StringC s = new StringC (
}
}
class StringC {
String s1;
String s2;
StringC( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}
7、 写出以下程序的运行结果为 s1!=s2 。
class StringTest1
{
public static void main(String[] args)
{
String s1=
String s2=new String(
if(s1==s2){

}else{

}
}


1、 编译Java Applet 源程序文件产生的字节码文件的扩展名为( B )。
A、java B、class C、html D、exe
2、 Java application中的主类需包含main方法,main方法的返回类型是什么?
( D )
A、int B、float C、double D、void
3、 当浏览器暂时离开含applet 程序的页面时,以下选项中的哪个方法将被执
行?( )
A、init() B、start() C、destroy() D、stop()
C、Applet D、Dialog?
4、 以下标识符中哪项是不合法的( A )
A、const B、$$double C、hello
B、D、BigMeaninglessName
5、 以下哪项可能包含菜单条( B
A、Panel B、Frame

C、Applet D、Dialog
6、 以下关于构造函数的描述错误的是( )。
A、构造函数的返回类型只能是void型。
B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。
C、构造函数的主要作用是完成对类的对象的初始化工作。
D、一般在创建新对象时,系统会自动调用构造函数。
7、 以下关于继承的叙述正确的是( A )。
A、在Java中类只允许单一继承
B、在Java中一个类只能实现一个接口
C、在Java中一个类不能同时继承一个类和实现一个接口
D、在Java中接口只允许单一继承
8、 在编写Java Applet程序时,若需要对发生的事件作出响应和处理,一般需
要在程序的开头写上( D )语句。
A、import .*
B、B、import .*
C、import .*
D、import ;
9、 下列哪些语句关于Java内存回收的说明是正确的? ( B )
A、程序员必须创建一个线程来释放内存
B、内存回收程序负责释放无用内存
C、内存回收程序允许程序员直接释放内存
D、内存回收程序可以在指定的时间释放内存对象
10、


有以下方法的定义,请选择该方法的返回类型( D )。
ReturnType method(byte x, double y)
{


return (short)xy*2;
}
A、byte B、short C、int D、double
11、 有以下程序片段,下列哪个选项不能插入到行1。( D )
1.
class Interesting{
3.}
A、import .*; B、package mypackage;
C、class OtherClass{ } D、public class MyClass{ }
12、 以下哪项是接口的正确定义?( B )
A、 interface B
{ void print() { } }
B、 abstract interface B
{ void print() }
13、 abstract interface B extends A1,A2 .}的重载函数?( D )
A、void? aMethod(?){...}
B、public?int? aMethod(){...}
C、public?void? aMethod ( ){...}
D、public?int? aMethod?(?int?m){...}
14、 A派生出子类B?,B派生出子类C,并且在Java源代码中有如下声明:
1. A a0=new A();
2. A? a1 =new B();
3. A a2=new C();
问以下哪个说法是正确的??( )
A、只有第1行能通过编译 ?
B、第1、2行能通过编译,但第3行编译出错
C、第1、2、3行能通过编译,但第2、3行运行时出错
D、第1行、第2行和第3行的声明都是正确的?
15、 假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错
误的?( D )
class A
{ int i;
static String s;
void method1() { }
static void method2() { }
}
A、;B、(); C、(); D、()
16、 有如下代码段:
1)
2) { if(unsafe()){;
public class TestString
{ public static void main(String args[ ])
{ StringC s = new StringC (
}


}
class StringC {
String s1;
String s2;
StringC( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}
1、 写出以下程序的功能。
import .*;
public class C {
public static void main(String[] args) throws IOException {
File inputFile = new File(“
File outputFile = new File(“
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = () ) != -1) (c);
();
(); }
}
2、 写出以下程序的功能。
class Test
{ public static void main(String[] args)
{ String s;
char c;
int upper,lower;
upper=lower=0;
s=args[0];
for (int i=0;i<();i++)
{ c=(i);
if(c>='a' && c<='z') lower++;
if(c>='A' && c<='Z') upper++; }
}
}
3、 写出以下程序的运行结果。
import .*;
public class Vec{
public static void main(String[] args) {
String[] s;
s=new String[2];
s[0]=new String(
s[1]=new String(
Vector v = new Vector();
for(int i = 0; i <2; i++) (s[i]);
(new String(
Enumeration e = ();
while())
(


for(int i = 0; i < () i++) +
}
}
4、 写出以下程序的运行结果。
class StaticTest {
static int x=1;
int y;
StaticTest()
{ y++; }
public static void main(String args[ ]){
StaticTest st=new StaticTest();


st=new StaticTest();

}
static { x++;}
}
5、 阅读以下程序,写出输出结果。
class First{
public First(){
aMethod(); }
public void aMethod(){
First class”);}
}
public class Second extends First{
public Second(){
aMethod(); }
public void aMethod(){
Second class”);}
public static void main(String[ ] args){
new Second( ); }
}
6、 写出以下程序的运行结果。
public class A
{
public static void main(String[ ] args)
{ test(15,26,4) ); }

static int test(int x, int y, int z)
{ return test( x, test(y,z) ); }

static int test(int x,int y)
{ if(x>y) return x;
else return y; }
}
7、 写出以下程序的运行结果。
class MyException extends Exception{
public String toString( ){ return
}


public class ExceptionDemo{
public static void mySqrt(int a) throws MyException {
if( a<0 ) throw new MyException();
}
public static void main( String args[] ){
try{ mySqrt(25 ); mySqrt(-5 ); }
catch( MyException e ){
}
}
8、 写出以下程序的功能。
public class TestArray
{ public static void main(String args[ ]){
int i , j
int a[ ] = {1,3,2,5,4};
for ( i = 0 i < i ++ ) {
int k = i;
for ( j = i j < j++ )
if ( a[j]>a[k] ) k = j;
int temp =a[i];
a[i] = a[k];
a[k] = temp; }
for ( i =0 i<; i++ )

);
}
}



一、选择题(每道题只有一个正确答案,每小题2分,共30分)15道题
1、关于Java语言叙述错误的是:( C)
A.Java语言具有跨平台性
B.Java是一种面向对象的语言
C.Java语言中的类可以多继承
D.Java的垃圾收集机制自动回收程序已不再使用的对象
2、以下叙述正确的是:( B)的确台a
A.构造方法必须是public方法
B.main方法必须是public方法
C.Java应用程序的文件名可以是任意的
D.构造方法应该声明为void类型
3、关于Java中数据类型叙述正确的是:( B)
A、整型数据在不同平台下长度不同
B.boolean类型数据只有2个值,true和false
C.数组属于简单数据类型
D.Java中的指针类型和C语言的一样
4、设 int x=1,float y=2,则表达式 x y的值是:( D)
A.0
B.1
C.2
D.以上都不是
5、以下语句有语法错的是:( A)
A.int x=1;y=2;z=3
B.for (int x=10,y=0;x>0;x++);
C.while (x>5);
D.for(; );
6、关于类和对象的叙述正确的是:( A)
A.Java的类分为两大部分:系统定义的类和用户自定义的类


B.类的静态属性和全局变量的概念完全一样,只是表达形式不同
C.类的成员至少有一个属性和一个方法
D.类是对象的实例化
7、以下有关构造方法的说法,正确的是:( A)
A.一个类的构造方法可以有多个
B.构造方法在类定义时被调用
C.构造方法只能由对象中的其它方法调用
D.构造方法可以和类同名,也可以和类名不同
8、以下有关类的继承的叙述中,正确的是:( D)
A.子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属

B.子类只能继承父类的方法,不能继承父类的属性
C.子类只能继承父类的非私有属性,不能继承父类的方法
D.子类不能继承父类的私有属性
9、下列属于容器的组件有:( B)
A.JButton
B.JPane
C.Canvas
D.JTextArea
10、void的含义:( C)
A.方法体为空
B.定义的方法没有形参
C.定义的方法没有返回值
D.方法的返回值不能参加算术运算
11、关于Java中异常的叙述正确的是:( D)
A.异常是程序编写过程中代码的语法错误
B.异常是程序编写过程中代码的逻辑错误
C.异常出现后程序的运行马上中止


D.异常是可以捕获和处理的
12、所有的异常类皆继承哪一个类?( C)
A.
B.
C.
D.
13、下面哪个不是java语言中的关键字?( B)
A.long
B.sizeof
C.instanceof
D.const
14、为实现进程之间的通信,需要使用下列那种流才合适?(D)
A.Data stream
B.File stream
C.Buffered stream
D.Piped stream
15、在复选框中移动鼠标,然后单击一选项,要捕获所选项必需实现哪个接口?
(D)
A.ActionListener
B.MouseListener
C.MouseMotionListern
D.ItemListener
二、填空题(每空1分,共20分)
1、面向对象程序设计所具有的基本特征是:___抽象 性___,_封装性___,_继承
性__,_多态性__
2、数组x定义如下
int x[ ][ ]=new int[3][2]
则 x..length的值为____3________,


x[0].length的值为_____2_______。
3、Java中实现多线程一般使用两 种方法,一是___继承Thread类_________,
二是_____实现Runnable方 法__________
4、Java的图形用户界面设计中,有很多布局管理器用来摆放组件的位置 ,一般
用到的布局管理器有(列出四种即可)__FlowLayout_____,___GridL ayout_____,
__BorderLayout_____,___CardLayout__ _____
5、Applet常用的方法是:__init()_、__run()__、__sto p()__和destroy()。
三、阅读程序,写出程序的输出结果(每题5分,共20分)
1、class A{
private int privateVar;
A(int _privateVar){
privateVar=_privateVar;
}
boolean isEqualTo(A anotherA){
if ==
return true;
else
return false;
}
}
public class B{
public static void main(String args[]){
A a = new A(1);
A b = new A(2);

}
}
程序的输出结果为:____false_____


2、class A {
double f(double x, double y) {
return x * y;
}
}
class B extends A {
double f(double x, double y) {
return x + y;
}
}
public class Test {
public static void main(String args[]) {
B obj = new B();

}
}
程序的输出结果为:__ The program output is 10_
3、public class Unchecked {
public static void main(String[] args) {
try {
method();
} catch (Exception e) {

} finally {

}
}
static void method() {


try {
wrench();

} catch (ArithmeticException e) {

} finally {

}

}
static void wrench() {
throw new NullPointerException();
}
}
程序的输出结果为:
E
A
B
4、public class Test {
public static void main(String[] args) {
int x;
int a[] = { 0, 0, 0, 0, 0, 0 };
calculate(a, a[5]);


}

static int calculate(int x[], int y) {


for (int i = 1; i < i++)
if (y <
x[i] = x[i - 1] + 1;
return x[0];
}
}
程序的输出结果为:
the value of a[0] is 0
the value is a[5] is 5
一、单选择题(每小题2分,共10分)
1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文
件的扩展名为( )。
A..java B. .class
C..html D. .exe
2、设 x = 1 , y = 2 , z = 3,则表达式 y+=z--++x 的值是( )。
A. 3 B. 3. 5
C. 4 D. 5
3、在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( )
方法来完成一些画图操作。
A. start( ) B. stop( )
C. init( ) D. paint( )
4、不允许作为类及类成员的访问控制符的是( )。
A. public B. private
C. static D. protected
5、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使 用类
名AB作为前缀就可以调用它,该方法头的形式为( )。
A. static void method( ) B. public void
method( )
C. final void method( ) D. abstract void
method( )

二、填空题(每空格1分,共20分)
1、开发与运行Java程序需要经过的三个主要步骤
为 、

和 。
2、如果一个Java Applet源程序文件只定义有一个类,该类的类名为MyApple t,
则类MyApplet必须是 类的子类并且存储该源程序
文件的文件名为 。


3、如果一个Java Applet程序文件中定义有3个类,则使用Sun公司的JDK编

器 编译该源程序文件将产生 个文件名
与类名相同而扩展名为 的字节码文件。
4、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码

用 字节内存空间,这样,无论是中文字符还是英文字符,都是

用 字节内存空间。
5、设 x = 2 ,则表达式 ( x + + )/3 的值是 。
6、若x = 5,y = 10,则x < y和x >= y的逻辑值分别为 和 。
7、 方法是一种仅有方法头,没有具体方法体和操作实现的方法,
该方法必须在抽象类之中定义。 方法是不能被当前类的子类重新定
义的方法。
8、创建一个名为 MyPackage 的包的语句
是 ,
该语句应该放在程序的位置
为: 。
9、设有数组定义:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执
行以下几个语句后的输出结果是 。
int s = 0
for ( int i = 0 ; i < i + + )
if ( i % 2 = = 1 ) s += MyIntArray[i]
s );
10、在Java程序中,通过类的定义只能实现 重继承,但通过接口的
定义可以实现 重继承关系。

三、写出下列程序完成的功能。(每小题5分,共20分)

1、public class Sum
{ public static void main( String args[ ])
{ double sum =
for ( int i = 1 i <= 100 i + + )
sum += (double) i

}
}

2、 import .*
public class Reverse
{ public static void main(String args[ ])
{ int i , n =10
int a[ ] = new int[10];
for ( i = 0 i < n i ++ )


try {
BufferedReader br = new BufferedReader(
new InputStreamReader);
a[i] = ( ));
public class abc
{ public static void main(String args[])
{ new FrameOut(); }
}
class FrameOut extends Frame
public class abc
{ public static void main(String args[])
{ SubClass sb = new SubClass( );
));
}
}
class SuperClass
{ int a = 10 , b = 20 }
class SubClass extends SuperClass
{ int max( ) { return ((a>b)?a:b); } }

四、写出下面程序的运行结果(每小题10分,共30分)
1、 import .*;
public class abc
{ public static void main(String args[ ])
{ AB s = new AB(VA.
));
}
}
class AB {
String s1;
String s2;
AB( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}

2、 import .*
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 < i ++ )


if ( a[i]%3 = = 0 ) s += a[i]

}
}

3、import .* ;
public class abc
{
public static void main(String args[ ])
)
{ }
}
class SubClass extends SuperClass
{ int c;
SubClass(int aa,int bb,int cc)
{ super(aa,bb);
c=cc;
}
}
class SubSubClass extends SubClass
{ int a;
SubSubClass(int aa,int bb,int cc)
{ super(aa,bb,cc);
a=aa+bb+cc;
}
void show()
{ }
}

五、使用Java语言编写程序。(每小题10分,共20分)

1、编写一个字符界面的Java Application 程序,接受用户输入的10个整数,
并输出这10个整数的最大值和最小值。

2、编写一个完整的Java Applet 程序使用复数类Complex验证两个复数 1+2i
和3+4i 相加产生一个新的复数 4+6i 。
复数类Complex必须满足如下要求:
(1) 复数类Complex 的属性有:
RealPart : int型,代表复数的实数部分
ImaginPart : int型,代表复数的虚数部分
(2) 复数类Complex 的方法有:
Complex( ) : 构造函数,将复数的实部和虚部都置0
Complex( int r , int i ) : 构造函数,形参 r 为实部的初值,i为虚部的初
值。


Complex complexAdd(Complex a) : 将当前复数对象与形参复数对象相
加,所得的结果仍是一个复数值,返回给此方法的调用者。
String ToString( ) : 把当前复数对象的实部、虚部组合成 a+bi 的字符串
形式,其中a 和 b分别为实部和虚部的数据。


《JAVA语言程序设计》期末考试模拟试题
参考答案及评分标准

一、单选择题(每小题2分,共10分)
1、B 2、A 3、D 4、C 5、A

二、填空题(每空格1分,共20分)
1、编辑源程序、编译生成字节码、解释运行字节码
2、Applet、MyApplet
3、、3、 . class
4、2 、2
5、0
6、true 、 false
7、抽象(abstract)方法、最终(final)方法
8、package MyPackage 应该在程序第一句。
9、120
10、单、多

三、写出下列程序完成的功能。(每小题5分,共20分)
1、计算 11+12+13+...+1100 的值。
2、从标准输入(即键盘)读入10个整数存入整型数组a中,然后逆序输出这10
个整数。
3、创建一个标题为按钮的窗框,窗框中显示有按下我字样的按钮。
4、求两个数的最大值。

四、写出下面程序的运行结果(每小题10分,共30分)
1、Hello! I love JAVA.
2、s = 180
3、a=60
b=20
c=30

五、使用Java语言编写程序。(每小题10分,共20分)
1、参考程序如下:
import .*
public class abc
{
public static void main(String args[ ])


{ int i , n = 10 , max = 0 , min = 0 , temp = 0;
try {
BufferedReader br = new BufferedReader(
new InputStreamReader);
max = min = ( ));
} catch ( IOException e ) { }
for ( i = 2 i <= n i ++ ) {
try {
BufferedReader br = new BufferedReader(
new InputStreamReader);
temp = ( ));
if (temp > max ) max=temp;
if (temp < min) min=temp;
} catch ( IOException e ) { }
}

}
}

2、参考程序如下:
import .*
import .*
public class abc extends Applet
{
Complex a,b,c
public void init( )
{
a = new Complex(1,2);
b = new Complex(3,4);
c = new Complex();
}

public void paint(Graphics g)
{
c=(b);
(第一个复数:
(第二个复数:
(两复数之和:
}
}

class Complex
{
int RealPart lass”后缀的字节码文件。(Y)


3、Java Applet是由独立的解释器程序来运行的。(N)
4、Java Application是由独立的解释器程序来运行的。(Y)
5、Java Applet的字节码文件必须嵌入HTML的文件中并由负责解释HTML
文 件的WWW浏览器充当解释器来解释运行。(Y)
7、Java源程序是由类定义组成的,每个程序可 以定义若干个类,但只有
一个类是主类。(Y)
8、Java中数组的元素只能是简单数据类型的量。(N)
9、Vector类中的对象不能是简单数据类型。(Y)
10、Java的String类的对象既可以是字符串常量,也可以是字符串变量。
(N)
11、Java中用户自定义的图形界面元素也可以响应用户的动作,具有交互
功能。(N)
12、Java的屏幕坐标是以像素为单位,容器的左上角被确定为坐标的起点。
(Y)
13、在Java中,并非每个事件类都只对应一个事件。(Y)
14、一个类只能有一个父类,但一个接口可以有一个以上的父接口。(Y)
15、由继承性可知,程序中子类拥有的成员数目一定大于等于父类拥有的
成员数目。(N)
16、Java语言中的数组元素下标总是从0开始,下标可以是整数或整型表
达式。(N)
17、注释的作用是使程序在执行时在屏幕上显示class StaticStuff
2. {
3. static int x=15;
4. static {x*=3;}
5. public static void main(String args[])
6. {
7. }
9. static {x=3;}
}
(A) 4行与9行不能通过编译,因为缺少方法名和返回类型
(B) 9行不能通过编译,因为只能有一个静态初始化器
(C) 编译通过,执行结果为:x=15
(D) 编译通过,执行结果为:x=3
14、关于以下程序代码的说明正确的是( C)
1. class HasStatic{


2. private static int x = 100;
3. public static void main(String args[]){
4. HasStatic hs1 = new HasStatic();
5. ++;
6. HasStatic hs2 = new HasStatic();
7. ++;
8. hs1=new HasStatic();
9. ++;
10. = ”+x);
11. }
12. }
(A) 5行不能通过编译,因为引用了私有静态变量
(B) 10行不能通过编译,因为x是私有静态变量
(C) 程序通过编译,输出结果为: x=103
(D) 程序通过编译,输出结果为:x=100
15、以下选项中循环结构合法的是( C)
(A) while(int i<7){
i++;
is ”+i);
}
(B) int j=3;
while(j){
j is ”+j);
}
(C) int j=0;
for(int k=0;j+k!=10;j++,k++){
is ”+j+ “ k is ”+k );
}
(D) int j=0;
do{
is ”+j++);
if (j==3){continue loop;}
}while(j<10);
16、类Text1定义如下:(B)


public class Test1{
public float aMethod(Float a, float b){}
***
}
将以下哪种方法插入行 *** 是不合法的。( )
(A) public float aMethod(float a,float b,float c){}
(B) public float aMethod(float c,float d){}
(C) public int aMethod(int a,int b){}
(D) public float aMethod(int a,int b,int c){}
17、创建字符串s: s=new String(“xyzy”);以下哪条语句将改变s( D)
(A) (“a”) (B) (s)
(C) (3) (D) 以上语句都不会
18、关于以下程序段,正确的说法是( B)
String s1 = “ac”+ “def”;
Strimg s2 = new String(s1);
if(s2))
succeeded”);
(A) 行4与行6都将执行 (B)行44执行,行6不执行
(C) 行6执行,行4不执行 (D) 行4、行6都不执行
19、关于以下代码段的说法正确的是(D )
String s = “abcde”;
StringBuffer s1 = new StringBuffer(“abcde”);
if(s1))
s1 = null;
if(s))
s=null;
(A) 第1行编译错误,String的构造器必须明确调用
(B) 第3行编译错误,因为s1与s2有不同的类型
(C) 编译成功,但执行时在第5行有异常抛出
(D) 编译成功,执行过程中也没有异常抛出
20、以下说法哪项是正确的( A)
class MyListener extends MouseAdapter implements MouseListener{
public void mouseEnter(MouseEvent mev){


entered.”);
}
}
(A) 以上代码可通过编译
(B) 不能通过编译,因为没有实现MouseListener接口中的所有方法
(C) 不能通过编译,因为类头定义不能分行
(D) 能通过编译,若组件用该类作为Mouse的监听者并且接收了
mouse- exited事件,则在执行过程中会抛出异常
21、关于以下程序段的说法,正确的是( A)
1. class MyListener implements
2. ActionListener,ItemListener{
3. public void actionPerformed(ActionEvent ae){
4. public void itemStateChanged(ItemEvent ie){
6. }
8. }
(A) 可通过编译
(B) 第2行产生编译错误
(C) 第3行产生编译错误
(D) 第5行产生编译错误
22、通过调用new JList(10,false)创建一个列表,关于该列表的几个说法
哪项是错误的。( D)
(A) 该列表不支持复选
(B) 该列表一次可显示10个选项
(C) 根据需要该列表可能有垂直滚动条
(D) 该列表有10个选项
23、以下哪项可能包含菜单条( B)
(A) JPanel (B) JFrame (C) Applet (D) JDialog
24、以下代码完成画线功能,指出所画线的颜色( C)
1. (0,0,100,100);
(A) red (B) green (C) yellow (D) cyan
25、关于以下代码所画图形的说明,正确的是( B)
1.;
2. (10,10,10,50);
3.


4. (100,100,150,150);
(A) 一条40像素长的垂直红线,一个边长为150像素的红色四方形
(B) 一条40像素长的垂直黑线,一个边长为150像素的红色四方形
(C) 一条40像素长的垂直黑线,一个边长为150像素的红色四方形
(D) 一条40像素长的垂直红线,一个边长为150像素的红色四方形
一、 程序阅读
1、阅读以下程序,输出结果为 。(21)
class D{
public static void main(String args[])
int d=21;
Dec dec=new Dec( );
(d);
Dec{
public void decrement(int decMe){
decMe = decMe - 1;
}
}
2、以下程序的输出结果为 。(结果为: Boy)
public class Short{
public static void main(String args[ ]) {
StringBuffer s = new StringBuffer(“Boy”);
if(( )<3)&& (“男孩”) . equals(“False”)))
;
结果为: ”+s);
}
}
3、以下程序段的输出结果为 。(Message four)
int x=0,y=4, z=5;
if ( x>2){
if (y<5){
one”);
}
else {


two”);
}
}
else if(z>5){
three”);
}
else {
four”);
}
4、以下程序段的输出结果为 。.)
int j=2;
switch ( j ) {
case 2:
2+1 :

default:
is “+j);
break;
}
5、以下程序段的输出结果为 。(int)
class Cruncher{
void crunch( int i ){
crunch(String s){
static void main(String args[ ]){
Cruncher crun=new Cruncher ( );
char ch=’p’;
(ch);
}
}
6、阅读以下程序,写出输出结果 。(99)
class Q6{
public static void main(String args[ ]){
Holder h=new Holder( );


=100;
(h);
}
}
class Holder{
public int held;
public void bump(Holder theHolder){
- -;
}
}
7、阅读以下程序,请写出输出结果 。(true)
public class EqualsMethod {
public static void main(String[] args) {
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
1、 application中的主类需包含main方法,main方法的返回类型是什么?
( D )
A、int B、float C、double D、void
2、 有以下方法的定义,请选择该方法的返回类型( D )。
ReturnType method(byte x, double y)
{
return (short)xy*2;
}
A、byte B、short C、int D、double
3、 在编写Java Applet程序时,若需要对发生的事件作出响应和处理,一般需
要在程序的开头写上( D )语句。
A、import .* B、import .*
C、import .* D、import
4、 容器Panel和Applet缺省使用的布局编辑策略是( A )
A、BorderLayout B、FlowLayout C、GridLayout D、CardLayout
5、 以下哪个不是Java的关键字?( A )
A、TRUE B、const C、super D、void
6、 有程序如下,关于程序的描述哪个是正确的?( A )
public class Person{
i. static int a[] = new int[10];
ii. public static void main(String a[])
iii. { }


}

A、编译将产生错误

C、正确,输出0
B、编译时正确,但运行时将产生错误
D、正确,输出?null
7、 以下关于构造函数的描述错误的是( A )。
A、构造函数的返回类型只能是void型。
B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。
C、构造函数的主要作用是完成对类的对象的初始化工作。
D、一般在创建新对象时,系统会自动调用构造函数。
8、 有语句String s=”hello world”; ,以下操作哪个是不合法的?( )
A、int i=(); B、s>>>=3; C、String ts=(); D、String t=s+”!”;
9、 有程序片段如下,以下哪个表示式的结果为true?( A )
Float s=new Float;
Float t=new Float;
Double u=new Double;
A、s==t B、(t) C、(s) D、(u)
10、 欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是
正确的 ?(B)
A、ArrayList myList=new Object()
B、List myList=new ArrayList()
C、ArrayList myList=new List()
D、List myList=new List();
11、 paint()方法使用哪种类型的参数? (A)
A、Graphics B、Graphics2D C、String D、Color
12、 指出正确的表达式 (C)
A、 byte=128; B、Boolean=null; C、 long l=0xfffL; D、 double=;
13、 指出下列程序运行的结果 (B)
public class Example{
String str=new String(
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
,;


}


public void change(String str,char ch[]){
str=
ch[0]='g';
}
}
A、 good and abc B、good and gbc C、 test ok and abc D、test ok and
gbc
14、 运行下列程序, 会产生什么结果 (A)
public class X extends Thread implements Runable{
public void run(){

}
public static void main(String args[])
{
Thread t=new Thread(new X());
();
}
}
A、 第一行会产生编译错误 B、 第六行会产生编译错误
C、 第六行会产生运行错误 D、 程序会运行和启动
15、 要从文件文件中读出第10个字节到变量C中,下列哪个方法适合? (B)
A、FileInputStream in=new FileInputStream(
B、FileInputStream in=new FileInputStream(
C、FileInputStream in=new FileInputStream(
D、RandomAccessFile in=new RandomAccessFile(
16、 容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器
大小的变化而改变? (B)
CardLayout
FlowLayout
BorderLayout
GridLayout
17、 给出下面代码: (C)
public class Person{
static int arr[] = new int[10];
public static void main(String a[])
{



}
}

那个语句是正确的?
A、 编译时将产生错误; B、编译时正确,运行时将产生错误;
C、 输出零; D、输出空。
18、 下列哪些语句关于内存回收的说明是正确的? (B)
A、 程序员必须创建一个线程来释放内存;
B、 内存回收程序负责释放无用内存
C、 内存回收程序允许程序员直接释放内存
D、 内存回收程序可以在指定的时间释放内存对象
19、 下列代码哪几行会出错: (C)
1) public void modify() {
2) int I, j, k;
3) I = 100;
4) while ( I > 0 ) {
5) j = I * 2;
6) (
7) k = k + 1;
8) I--;
9) }
10) }
A、 line 4 B、 line 6 C、 line 7 D、
一、 程序阅读
1、 阅读以下程序:
class Exp1
{
public static void main(String[] args)
{
String s,s1=
char c;
s=args[0];
for (int i=0;i<();i++)
{ c=(i);
if(c>='a' && c<='z'){
s1=s1+(c);
}else{
s1=s1+(c); }
line 8


}
}
}
若在dos命令行输入:java Exp1 cHINA,则输出为
China 。
2、 阅读以下程序:
import .*;
public class AboutFile{
public static void main(String[ ] args)throws IOException{
BufferedReader b=new BufferedReader (new InputStreamReader);
String s;
s=();
is:”+s);
}
}
运行以上程序,若从键盘输入:
java<回车>
则输出结果为 String is: java 。
3、 以下程序段的输出结果为 。
public class C
{
public static void main(String args[ ]){
int i , j
int a[ ] = { 5,1,3,9,7};
for ( i = 0 i < i ++ ) {
int k = i;
for ( j = i j < j++ )
if ( a[j] int temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for ( i =0 i<; i++ )

);
}
}
4、 阅读以下程序,写出输出结果 Animal Cat 。
class Animal {
Animal() {
( }
}
public class Cat extends Animal {
Cat() {
( }

public static void main(String[] args) {
Cat kitty= new Cat(); }
}


5、 阅读以下程序,输出结果为 1 。
import .*;
public class ATest{
public static void main(String args[]) {
SubClass sb = new SubClass( );
)); }
}
class SuperClass{
int a = 10 , b = -3
}
class SubClass extends SuperClass{
int funOfMod( ) { return a%b; }
}
6、 以下程序段的输出结果为 int, int 。
class Cruncher{
void crunch( int i ){
}
void crunch(String s){
}
public static void main(String args[ ]){
Cruncher crun=new Cruncher ( );
char ch=’h’;
int i=12;
(ch);;
public class TestString
{ public static void main(String args[ ])
{ StringC s = new StringC (
}
}
class StringC {
String s1;
String s2;
StringC( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}
7、 写出以下程序的运行结果为 s1!=s2 。
class StringTest1
{
public static void main(String[] args)
{
String s1=
String s2=new String(
if(s1==s2){

}else{

}
}


1、 编译Java Applet 源程序文件产生的字节码文件的扩展名为( B )。
A、java B、class C、html D、exe
2、 Java application中的主类需包含main方法,main方法的返回类型是什么?
( D )
A、int B、float C、double D、void
3、 当浏览器暂时离开含applet 程序的页面时,以下选项中的哪个方法将被执
行?( )
A、init() B、start() C、destroy() D、stop()
C、Applet D、Dialog?
4、 以下标识符中哪项是不合法的( A )
A、const B、$$double C、hello
B、D、BigMeaninglessName
5、 以下哪项可能包含菜单条( B
A、Panel B、Frame

C、Applet D、Dialog
6、 以下关于构造函数的描述错误的是( )。
A、构造函数的返回类型只能是void型。
B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。
C、构造函数的主要作用是完成对类的对象的初始化工作。
D、一般在创建新对象时,系统会自动调用构造函数。
7、 以下关于继承的叙述正确的是( A )。
A、在Java中类只允许单一继承
B、在Java中一个类只能实现一个接口
C、在Java中一个类不能同时继承一个类和实现一个接口
D、在Java中接口只允许单一继承
8、 在编写Java Applet程序时,若需要对发生的事件作出响应和处理,一般需
要在程序的开头写上( D )语句。
A、import .*
B、B、import .*
C、import .*
D、import ;
9、 下列哪些语句关于Java内存回收的说明是正确的? ( B )
A、程序员必须创建一个线程来释放内存
B、内存回收程序负责释放无用内存
C、内存回收程序允许程序员直接释放内存
D、内存回收程序可以在指定的时间释放内存对象
10、


有以下方法的定义,请选择该方法的返回类型( D )。
ReturnType method(byte x, double y)
{


return (short)xy*2;
}
A、byte B、short C、int D、double
11、 有以下程序片段,下列哪个选项不能插入到行1。( D )
1.
class Interesting{
3.}
A、import .*; B、package mypackage;
C、class OtherClass{ } D、public class MyClass{ }
12、 以下哪项是接口的正确定义?( B )
A、 interface B
{ void print() { } }
B、 abstract interface B
{ void print() }
13、 abstract interface B extends A1,A2 .}的重载函数?( D )
A、void? aMethod(?){...}
B、public?int? aMethod(){...}
C、public?void? aMethod ( ){...}
D、public?int? aMethod?(?int?m){...}
14、 A派生出子类B?,B派生出子类C,并且在Java源代码中有如下声明:
1. A a0=new A();
2. A? a1 =new B();
3. A a2=new C();
问以下哪个说法是正确的??( )
A、只有第1行能通过编译 ?
B、第1、2行能通过编译,但第3行编译出错
C、第1、2、3行能通过编译,但第2、3行运行时出错
D、第1行、第2行和第3行的声明都是正确的?
15、 假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错
误的?( D )
class A
{ int i;
static String s;
void method1() { }
static void method2() { }
}
A、;B、(); C、(); D、()
16、 有如下代码段:
1)
2) { if(unsafe()){;
public class TestString
{ public static void main(String args[ ])
{ StringC s = new StringC (
}


}
class StringC {
String s1;
String s2;
StringC( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}
1、 写出以下程序的功能。
import .*;
public class C {
public static void main(String[] args) throws IOException {
File inputFile = new File(“
File outputFile = new File(“
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = () ) != -1) (c);
();
(); }
}
2、 写出以下程序的功能。
class Test
{ public static void main(String[] args)
{ String s;
char c;
int upper,lower;
upper=lower=0;
s=args[0];
for (int i=0;i<();i++)
{ c=(i);
if(c>='a' && c<='z') lower++;
if(c>='A' && c<='Z') upper++; }
}
}
3、 写出以下程序的运行结果。
import .*;
public class Vec{
public static void main(String[] args) {
String[] s;
s=new String[2];
s[0]=new String(
s[1]=new String(
Vector v = new Vector();
for(int i = 0; i <2; i++) (s[i]);
(new String(
Enumeration e = ();
while())
(


for(int i = 0; i < () i++) +
}
}
4、 写出以下程序的运行结果。
class StaticTest {
static int x=1;
int y;
StaticTest()
{ y++; }
public static void main(String args[ ]){
StaticTest st=new StaticTest();


st=new StaticTest();

}
static { x++;}
}
5、 阅读以下程序,写出输出结果。
class First{
public First(){
aMethod(); }
public void aMethod(){
First class”);}
}
public class Second extends First{
public Second(){
aMethod(); }
public void aMethod(){
Second class”);}
public static void main(String[ ] args){
new Second( ); }
}
6、 写出以下程序的运行结果。
public class A
{
public static void main(String[ ] args)
{ test(15,26,4) ); }

static int test(int x, int y, int z)
{ return test( x, test(y,z) ); }

static int test(int x,int y)
{ if(x>y) return x;
else return y; }
}
7、 写出以下程序的运行结果。
class MyException extends Exception{
public String toString( ){ return
}


public class ExceptionDemo{
public static void mySqrt(int a) throws MyException {
if( a<0 ) throw new MyException();
}
public static void main( String args[] ){
try{ mySqrt(25 ); mySqrt(-5 ); }
catch( MyException e ){
}
}
8、 写出以下程序的功能。
public class TestArray
{ public static void main(String args[ ]){
int i , j
int a[ ] = {1,3,2,5,4};
for ( i = 0 i < i ++ ) {
int k = i;
for ( j = i j < j++ )
if ( a[j]>a[k] ) k = j;
int temp =a[i];
a[i] = a[k];
a[k] = temp; }
for ( i =0 i<; i++ )

);
}
}


史蒂文斯理工学院-劳动节的意义


初三历史复习-南京信息职业技术学院分数线


五年级下册作文-跳槽注意事项


德阳外国语学校-少数民族手抄报


写给党的一封信-李毅大帝语录


宁夏新华学院-情况汇报


sorry什么意思-音乐教师年度总结


大雁塔导游词-感受生命