一、單選擇題(每小題2分,共10分)
1、編譯Java Application 源程式檔案將產生相應的位元組碼檔案,這些位元組碼檔案的副檔名為( B )。
A. B. s
D.
2、 main方法是Java Application程式執行的入口點,關於main方法的方法頭以下哪項是合法的( B )?
A、public static void main( )
B、public static void main( String args[] )
C、public static int main(String [] arg )
D、public void main(String arg[] )
3、設 x = 1 , y = 2 , z = 3,則表示式 y+=z--/++x 的值是( A )。
A. 3 B. 3. 5
C. 4 D. 5
4、在Java Applet程式使用者自定義的Applet子類中,一般需要過載父類的( D )方法來完成一些畫圖操作。
A. start( ) B. stop( )
C. init( ) D. paint( )
5、不允許作為類及類成員的訪問控制符的是( C )。
A. public B. private
C. static D. protected
二、填空題(每空格1分,共20分)
1、開發與執行Java程式需要經過的三個主要步驟為 編輯 、
編譯 和 執行 。
2、如果一個Java Applet源程式檔案只定義有一個類,該類的類名為MyApplet,則類MyApplet必須是 類 Applet 的子類並且儲存該源程式檔案的檔名為 。
3、如果一個Java Applet程式檔案中定義有3個類,則使用Sun公司的JDK編譯器 javac 編譯該源程式檔案將產生 3 個檔名與類名相同而副檔名為 s 的位元組碼檔案。
三、寫出下面程式的執行結果(每小題14分,共28分)
1、
import .*;
5、設 x = 2 ,則表示式 ( x + + )/3 的值是 1 。
6、若x = 5,y = 10,則x 和x >= y的邏輯值分別為 true 和 false 。
7、 抽象 方法是一種僅有方法頭,沒有具體方法體和操作實現的方法,該方法必須在抽象類之中定義。 final 方法是不能被當前類的子類重新定義的方法。
8、建立一個名為MyPackage 的.包的語句是 package MyPackage; ,該語句應該放在程式的位置為: 第一行 。
9、設有陣列定義:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 則執行以下幾個語句後的輸出結果是 0 。
int s = 0 ;
for ( int i = 0 ; i
if ( i % 2 = = 1 ) s += MyIntArray ;
tln( s );
10、在Java程式中,通過類的定義只能實現 重繼承,但通過介面的定義可以實現 多 重繼承關係。
四、寫出下列程式完成的功能。(每小題14分,共42分)
1、
public class Sum{
public static void main( String args[ ]) {
double sum = 0.0 ;
for ( int i = 1 ; i
sum += 1.0/(double) i ;
tln( "sum="+sum );
}
}
sum=5.187377517639621
2、
import .* ;
public class Reverse{
public static void main(String args[ ]) {
int i , n =10 ;
int a[ ] = new int[10];
for ( i = 0 ; i
try {
public class abc{
public static void main(String args[ ]) {
String str1=" Hello!" ;
String str2=" I love JAVA." ;
tln(new AB(str1,str2));
tln(str2);
}
}
class AB {
String s1;
String s2;
AB( String str1 , String str2 ){
s1 = str1;
s2 = str2;
str2+=str1;
}
public String toString( ) {
return s1+s2;
}
}
2、
class Ex{
public static void main(String[] args) {
Fx f=new Fx(5);
}
Ex() {
tln("Ex,no-args");
}
Ex(int i) {
tln("Ex,int");
}
}
class Fx extends Ex{
Fx() {
super();
tln("Fx,no-args");
}
Fx(int i) {
this();
tln("Fx,int");
}
}