- 動物類
- 1.抽象方法:
- 沒有方法體的方法
- {代碼以報錯處}:Abstract methods do not specify a body
- 2.abstract 抽象的
- 3.抽象方法如何定義
- 【訪問權限符】 abstract 返回值 方法名();
- eg:
- public abstract void shout();
- 4.如何定義一個抽象類
- 【訪問權限符】 abstract class 類名{
- }
- eg:
- public abstract class Animal {
- }
- 5.注意:
- A.抽象方法一定要在抽象類中
- B.抽象類中可以有0 1 2 等抽象方法
- C.抽象類不能直接new本類 只能創建子類對象 抽象類一定要被繼承 Cannot instantiate the type Animal
- D.子類繼承父類 如果父類是抽象類 子類一定要實現父類裏所有的抽象方法 除非子類也是抽象類
- {代碼以報錯處}:The type Cat must implement the inherited abstract method Animal.shout()
- E.abstract關鍵字能修飾 類 方法
- 不能修飾 成員變量 構造方法
- F.抽象類中的成員 成員變量 構造方法 成員方法
- {代碼以報錯處}:The abstract method shout in type Animal can only be defined by an abstract class
- {代碼以報錯處}: Illegal modifier for the field name; only public, protected, private, static, final, transient & volatile are permitted
- {代碼以報錯處}: Illegal modifier for the constructor in type Animal; only public, protected & private are permitted
抽象
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.