2017年java期末考试试题

来源:文书网 1.14W

Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。下面是关于java期末考试试题,希望大家认真阅读!

2017年java期末考试试题

  一、单项选择题(本大题共 17 小题,每小题 2 分,共 34 分)

1. 下列关于Java程序的说法错误的是________。

A.一个类被编译成一个s字节码文件

B. Java程序是解释执行的,所以程序运行速度快,而且无需编译

C. Java程序可以实现跨平台

D.有且仅有一个包含main方法的主类,否则不能运行

2. 下列________是用于一般开发的Java开发工具标准版本。

A. Java EE B. Java ME C. Java SE D. JDK

3. 下列符合Java程序类名命名习惯的是________。

A. _iBoy B. Data

C. 4k@sina D. studentGrade

4. 下列数据定义错误的是________。

A. float f = 5; B. int d = (int)4.3;

C. byte c = -1186; D. final double PI = 3.14;

5. 下列程序片段运行的结果是________。

int a = 36; int b = (a++)%5; tln("a="+a+",b="+b);

A. a=36,b=0 B.a=37,b=2 C.a=36,b=1 D.a=37,b=1

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

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

和 。

2、如果一个Java Applet源程序文件只定义有一个类,该类的类名为MyApplet,则类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 < th ; i + + )

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

tln( s );

  三、写出下列程序完成的功能。(每小题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 ;

tln( "sum="+sum );

}

}

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] = eInt(Line( )); // 输入一个整数

} catch ( IOException e ) { } ;

for ( i = n-1 ; i >= 0 ; i ―― )

t(a[i]+" ");

tln( );

}

}

3、 import .*;

public class abc

{ public static void main(String args[])

{ new FrameOut(); }

}

class FrameOut extends Frame // Frame为系统定

{ Button btn; // 义的窗框类

FrameOut( )

{ super("按钮");

btn = new Button("按下我");

setLayout(new FlowLayout( ));

add(btn);

setSize(300,200);

show( );

}

}

4、import .*;

public class abc

{ public static void main(String args[])

{ SubClass sb = new SubClass( );

tln(( ));

}

}

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("Hello!","I love JAVA.");

tln(ring( ));

}

}

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 < th ; i ++ )

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

tln("s="+s);

}

}

3、import .* ;

public class abc

{

public static void main(String args[ ])

{ SubSubClass x = new SubSubClass(10 , 20 , 30);

();

}

}

class SuperClass

{ int a,b;

SuperClass(int aa , int bb)

{ a=aa; b=bb; }

void show( )

{ tln("a="+a+"nb="+b); }

}

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

{ tln("a="+a+"nb="+b+"nc="+c); }

}

热门标签