java语言试题及答案_JAVA语言程序设计期末考试题及答案.docx

这是一份关于JAVA语言程序设计的期末考试复习资料,包含单选题、填空题和程序运行结果分析,旨在帮助学生掌握JAVA编程的基础知识和应用技巧。
摘要由CSDN通过智能技术生成

JAVA语言程序设计期末考试题及答案

《JAVA语言程序设计》期末考试试题及答案1(应考必备题库)

一、单选择题

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、不允许作为类及类成员的访问控制符的是( )。

A. public

B. private

C. static

D. protected

4、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )。

A. static void method( )

B. public void method( )

C. final void method( )

D. abstract void method( )

5 给定java 代码如下,编译运行后,输出结果是()(选择一项)。

public class test

static int i;

public int aMethod()

i ;

return i;

public static void main (String args[])

Test test=new Test() ;

test.aMethod () ;

System.out.println (test.aMethod()) ;

a) 0 b) 1 c) 2 d) 3

二、填空题

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

编译生成字节码和解释运行字节码。

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

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

用2字节内存空间。

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

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

5、抽象(abstract) 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。最终(final)方法是不能被当前类的子类重新定义的方法。

6、创建一个名为 MyPackage 的包的语句是package MyPackage ; ,

该语句应该放在程序的位置为:应该在程序第一句。

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

int s = 0 ;

for (int i = 0 ; i

if ( i % 2 = = 1 )

s = MyIntArray[i] ;

System.out.println(s);

8、在Java程序中,通过类的定义只能实现单重继承,但通过接口的定义可以实现多重继承关系。

三、写出下面程序的运行结果

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;

public AB(String str1, String str2)

s1 = str1;

s2 = str2;

public String toString( )

return s1 s2;

运行结果:Hello! I love JAVA.

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

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

System.out.println("s=" s);

运行结果:s = 120

3、class Parent

String one, two;

public Parent(String a, String b)

one = a;

tw

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值