?? java.txt
字號:
《JAVA語言程序設計》期末考試模擬試題
( 適用對象:成人專科、開放專科計算機類專業 )
2001年6月
一、單選擇題(每小題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源程序文件只定義有一個類,該類的類名為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 < 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( "sum="+sum );
}
}
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 java.awt.*;
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 java.io.*;
public 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("Hello!","I love JAVA.");
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("s="+s);
}
}
3、import java.io.* ;
public class abc
{
public static void main(String args[ ])
{ SubSubClass x = new SubSubClass(10 , 20 , 30);
x.show();
}
}
class SuperClass
{ int a,b;
SuperClass(int aa , int bb)
{ a=aa; b=bb; }
void show( )
{ System.out.println("a="+a+"\nb="+b); }
}
class SubClass extends SuperClass
{ int c;
SubClass(int aa,int bb,int cc)
{ super(aa,bb);
c=cc;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -