1 / 35

OCPJP 考前複習

OCPJP 考前複習. 主講人: 戴玉佩. Day 1 大綱. 繼承 類別與實作介面 Overridding Metho d Costructors 多型 轉型與 instanceof Hiding Variable 與 Hiding Class Method. 繼承類別與實作 介面. 用來定義 is-a 關係 類別只能單一繼承類別 類別可以多重實作介面 介面可以多重繼承 任何 Java 類別若無宣告繼承,則會繼承 Object. 考題:繼承. ✔. ✔. 考題:繼承. ✔. ✔. 考題:繼承. ✔. 考題:繼承. ✔.

carol
Download Presentation

OCPJP 考前複習

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OCPJP考前複習 主講人:戴玉佩

  2. Day 1 大綱 • 繼承類別與實作介面 • Overridding Method • Costructors • 多型 • 轉型與instanceof • Hiding Variable 與Hiding Class Method

  3. 繼承類別與實作介面 • 用來定義is-a關係 • 類別只能單一繼承類別 • 類別可以多重實作介面 • 介面可以多重繼承 • 任何Java類別若無宣告繼承,則會繼承Object

  4. 考題:繼承 ✔ ✔

  5. 考題:繼承 ✔ ✔

  6. 考題:繼承

  7. 考題:繼承

  8. 繼承類別與實作介面 • 抽象類別 • 可以定義屬性、方法、建構子 • 可以定義抽象方法 • 介面 • 不可定義屬性、方法、建構子 • 只在此宣告public static final屬性 • 只可在此宣告public abstract method

  9. 考題:介面

  10. 考題:介面 ✔ ✔ ✔

  11. 考題:介面與抽象類別

  12. 考題:介面 interface Reloadable{ public void reload(); } class Edit{ public void edit(){} } interface Displayable { } Place here Place here Reloadable extends public void display(); Place here extends public void display(){} Reloadable implements public void display(); Edit

  13. Overriding Method • 實作Overriding Method時,方法定義務必 • 存取範圍一樣或更大 • 回傳型別一樣或子類別 • 方法名稱完全相同 • 參數列的參數個數與對應型別 • 拋出的Exception須一樣或更少

  14. 考題: Overriding Method ✔ ✔ ✔

  15. 考題: Overriding Method

  16. 考題: Overriding Method

  17. 考題:Overriding Method

  18. 考題:Overriding Method

  19. 考題:Overriding Method class Alpha{ public void bar(int… x){} public void bar(intx){} } public class Delta extends Alpha{ } private void bar(int x){} public void bar(int x){} public intbar(String x){return ”x";} public void bar(int x){} Place here public Alpha bar(int x){} public intbar(String x){return ”x";} Place here private void bar(intx, int y){} private void bar(intx, int y){} Place here public int bar(int x){return x;}

  20. 建構子 • 當super class沒有定義預設建構子時 • sub class必須在自己的建構子第一行用super(…)來呼叫父類別的建構子 • 否則該sub class將無法編譯

  21. 考題: 建構子 ✔ ✔

  22. 考題:建構子

  23. 考題:建構子

  24. 考題:建構子

  25. 多型 • 用上層型別宣告的變數來參考下層實體類別建立的物件 • 僅可使用該上層型別有定義的成員 • 但是可以執行到下層類別有實作的Overriding Method

  26. 考題: 多型

  27. 考題: 多型

  28. 考題: 多型

  29. 考題: 多型 ✔ ✔ ✔ ✔

  30. 考題:多型

  31. 考題:多型

  32. Hiding Variable • 屬性不可Override但可以被Hide • 執行時存取到的屬性是以參考變數的型別為依據

  33. 考題

  34. Day 2 大綱 • static、final • 列舉型別 • 巢狀類別 • Exception

  35. Day 3 大綱 • Collection • Generics • IO • 多執行緒 • 其他API

More Related