阿摩線上測驗
登入
首頁
>
程式語言
> 104年 - 104 鐵路特種考試_高員三級_資訊處理:程式語言#22432
104年 - 104 鐵路特種考試_高員三級_資訊處理:程式語言#22432
科目:
程式語言 |
年份:
104年 |
選擇題數:
0 |
申論題數:
5
試卷資訊
所屬科目:
程式語言
選擇題 (0)
申論題 (5)
一、請根據下列文法畫出輸入字串 abbddeffccg 所有可能的文法樹(亦稱文法剖析樹、剖
析樹)。並請討論此文法的問題。(20 分)
S → a X g
X → b X
X → b X c
X → b X c c
X → Y
Y → d Y
Y → d Y f
Y → d Y f f
Y → e
二、請用下例說明在 Java 程式語言裡,dynamic dispatching 的意義與運作方式。並且說明
最後印出的報表為何?(20 分)
import java.lang.*;
class test24 {
public static void main(String[] arg) {
B b = new C();
R r = new S();
System.out.println("r.m(b) = " + r.m(b) );
}
}
class A { }
class B extends A { }
class C extends B { }
class P {
int m(B x) { return 1; }
}
class Q extends P {
int m(A x) { return 2; }
}
class R extends Q {
int m(C x) { return 3; }
}
class S extends R {
int m(B x) { return 4; }
int m(C x) { return 5; }
三、在 C 程式語言裡,我們可以使用 union type。請舉例說明何謂 union type。在物件導向 程式語言裡,如 Java,我們如何達成 union type 相同的效果?請用你所提出的方法, 改寫你所提出的 union type 的範例。(20 分)
四、新的程式語言都會提供例外處理(exception handling)。請說明下列 Java 程式做例外
處理的可能流程。並且請說明 finally clause 的執行過程。(20 分)
public void writelist() throws ArrayIndexOutOfBoundsException {
PrintStream pStr = null;
try {
pStr = new PrintStream(
new BufferedOutputStream(
new FileOutputSteam("outfile")));
pStr.println("The 9th element is " +
victor.elementAt(9));
} catch (IOException e) {
System.err.println("i/o error");
} finally {
if (pStr != null) pStr.close();
}
}
五、記憶體是程式內部結構的一部分,記憶體的管理嚴重影響程式執行之效率。當程式 執行時,記憶體大約可以分成三種區塊,請問此三種區塊為何?各自的用途為何? 各自如何產生?各自如何消失?其優缺點為何?(20 分)