好文档 - 专业文书写作范文服务资料分享网站

《面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案3

天下 分享 时间: 加入收藏 我要投稿 点赞

面向对象程序设计 JAVA 语言程序设计》期末考试试题及部分答案

、单选择题 (每小题 2分,共 10分 )

1、编译 Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为 ( B

A. C.

.java .html

B. D.

.class .exe

) 。

2、 设 x = 1 , y = 2 , z = 3,则表达式 y+ = z ------ / —H x 的值是(A )。

A. C.

3 4

B. D.

3. 5 5

)方法来完成一些画图操

3、 在 Java Applet 程序用户自定义的 Applet 子类中,一般需要重载父类的 ( D 作。

A. start( ) C. init( )

B. D.

stop( ) paint( ) ( C )。 private protected

method 书写方法头,使得使用类名

4、不允许作为类及类成员的访问控制符的是

A. public C. static

B. D.

5、为 AB 类的一个无形式参数无返回值的方法

AB 作为前缀就可以调

用它,该方法头的形式为 ( A ) 。

A. static void method( ) C. final void method( )

B. public void method( ) D. abstract void method( )

二、填空题(每空格 1 分,共 20分)

1、 开发与运行Java程序需要经过的三个主要步骤为

编译生成字节码、

编辑源程序

解释运行字节码

、 。

2、 如果一个 Java Applet 源程序文件只定义有一个类,该类的类名为 MyApplet ,则类 MyApplet 必须是 Applet 、

类的子类并且存储该源程序文件的文件名为

MyApplet

3、 如果一个 Java Applet 程序文件中定义有 3个类,则使用 Sun 公司的 JDK 编译 器 javac.exe 编译该源程序文件将产生 为

. class 的字节码文件。

3

个文件名与类名相同而扩展名

4、 在Java的基本数据类型中,char型采用Unicode编码方案,每个 Unicode码占 用 用

2 2

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

5、 设 x = 2 ,则表达式 ( x + + )/3 的值是 0

6、 若 x = 5, y = 10,则 x < y 和 x >= y 的逻辑值分别为 true 和 false 。

7、 抽象(abstract)方法 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法

最终(final)方法

方法是不能被当前类的子类重新定义的方法。

, 。

必须在抽象类之中定义。

8、 创建一个名为 MyPackage 的包的语句是 package MyPackage ; 该语句应该放在程序的位置为:

应该在程序第一句

9、 设有数组定义: int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执行以下几个语句后的输出结 果是

120

int s = 0 ;

for ( int i = 0 ; i < MyIntArray.length ; i + + )

if ( i % 2 = = 1 ) s += MyIntArray[i] ;

System.out.println( s );

10、 在Java程序中,通过类的定义只能实现 单

重继承,但通过接口的定义可以实现

继承关系。

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

1 、 public class Sum

{ public static void main( String args[ ])

{ double sum = 0.0 ;

for ( int i = 1 ; i <= 100 ; i + + )

sum += 1.0/(double) i ; System.out.println( \

} }

2、 import java.io.* ;

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(System.in));

a[i] = Integer.parseInt(br.readLine( )); // 输入一个整数 } catch ( IOException e ) { } ; for ( i = n - 1 ; i >= 0 ; i

―― )

System.out.print(a[i]+\

System.out.println( );

}

3、 import

public

java.awt.*;

class static

abc void

main(String args[])

{ public

{ new FrameOut(); }

}

class FrameOut extends Frame // Frame 为系统定 { Button btn; // 义的窗框类

FrameOut( ) {

super(” 按钮\

btn = new Button(\按下我 \add(btn); setSize(300,200); show( );

} }

4、 import

public

java.io.*; class abc

{ public static void main(String args[])

{ SubClass sb = new SubClass( );

System.out.println(sb.max( ));

} }

class SuperClass { int a = 10 , b = 20 ; }

class SubClass extends SuperClass { int max( ) { return ((a>b)?a:b); } }

四、写出下面程序的运行结果 (每小题10分,共 30分) 1、 import java.io.*; public class abc {

public static void main(String args[ ]) {

AB s = new AB(\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;}

}

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 ( a[i]%3 = = 0 ) s += a[i] ;

System.out.println(\

}

}

3、 import java.io.* ;

public class abc

{

public static void main(String args[ ])

)

{ System.out.println(\

}

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()

{ System.out.println(\

}

五、使用 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分 )

《面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案3

面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案、单选择题(每小题2分,共10分)1、编译JavaApplication源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为(BA.C..java.htmlB.D..class.exe
推荐度:
点击下载文档文档为doc格式
0d3mx5ms5379c964hjsm5kaxd91bpl00ktq
领取福利

微信扫码领取福利

微信扫码分享