103年 鐵路特考 高員三級 資訊處理 程式語言 試卷

pdf
89.32 KB
2 頁
admin
侵權投訴
加載中. ..
PDF
103年公務人員特種考試警察人員考試
103年公務人員特種考試一般警察人員考試
103年特種考試交通事業鐵路人員考試試題 代號71060
別:高員三級鐵路人員考試
科:資訊處理
目:程式語言
考試時間:2小時
※注意:
禁止使用電子計算器。
不必抄題,作答時請將試題題號及答案依照順序寫在試卷上,於本試題上作答者,不予計分。
(請接背面)
全一張
正面
請比較類別(class)的使用者觀點(user view)及開發者觀點(developer view
的差異。(10 分)
二、請寫出下列敘述的正規表達式(regular expression):
“Each word must start with two digits, followed by a upper case letter, and then followed
by at least one letter either upper case or lower case.”10 分)
三、請問下列 Java 程式執行結果為何?(10 分)
import java.io.IOException;
public class throwException {
public static void main(String[] args) throws E {
try {E e1 = new E(“here comes e1”);
throw e1;
System.out.println(gets here); }
catch(E e1) { System.out.println(“catches e1”);}
}//main
}//throwException
class E extends IOException {
E(String message) { super(message); }
}// class E
四、請問下列 Java 程式輸出為何?(10 分)
public class C6 {
public static void main(String[] args) {
int [] a = new int[2];
int [] b = new int[2];
a[0] = 6;b[0] = 6;a[1] = 7;b[1] = 7;
System.out.println(a.equals(b));
}}
103年公務人員特種考試警察人員考試
103年公務人員特種考試一般警察人員考試
103年特種考試交通事業鐵路人員考試試題 代號71060
別:高員三級鐵路人員考試
科:資訊處理
目:程式語言
全一張
背面
五、請問下列 Java 程式輸出為何?(20 分)
import java.text.DecimalFormat;
public class C3 {
public static void main(String[] args) {
DecimalFormat d = new DecimalFormat("0.00");
double grosspay = 800.416;
System.out.println(d.format(grosspay));
grosspay = 1234.567;
System.out.printf("%1.2f", grosspay);
} }
六、下列為一物件導向程式:
class A { private int a1;
public void m1( ); { a1 = 1;}
public void m2( ); { a1 = 3;} }
class B extends A { private int b1; private int b2;
public void m2( ); { b1 = 1; b2 = 2;}
public void m3( ); { a1 = 2; } }
請說明其中的繼承(inheritance)及覆寫(overriding);
並請說明 class B 的物件內含那些資料欄位(data fields)?(20 分)
七、
請說明下列 main 程式執行情形。(10 分)
請以此程式解釋動態繫結(dynamic binding)。(10 分)
public class X
{public String whatIAm() {return “I’m an X.”;}}
public class Y extends X
{public String whatIAm() {return “I’m a Y.”;}}
public static void main(String[] args) throws IOException
{ X x;
BufferedReader reader = new BufferedReader
(new InputStreamReader(System.in));
if (reader.readLine().equals(“Go with X”)) x = new X();
else x = new Y();
System.out.println(x.whatIAm());
} // main
收藏 ⬇️ 下載