抽象


  1.   動物類
  2.   1.抽象方法:
  3.          沒有方法體的方法
  4.          {代碼以報錯處}:Abstract methods do not specify a body
  5.   2.abstract 抽象的
  6.  3.抽象方法如何定義
  7.   【訪問權限符】 abstract 返回值  方法名();
  8.    eg:
  9.        public abstract void shout();
  10.   4.如何定義一個抽象類
  11.     【訪問權限符】   abstract class  類名{
  12.   
  13.  }     
  14.    eg:
  15.       public abstract class Animal {
  16.      }
  17. 5.注意:
  18.  A.抽象方法一定要在抽象類中
  19.   B.抽象類中可以有0  1  2  等抽象方法
  20. C.抽象類不能直接new本類  只能創建子類對象  抽象類一定要被繼承 Cannot instantiate the type Animal
  21.  D.子類繼承父類 如果父類是抽象類 子類一定要實現父類裏所有的抽象方法  除非子類也是抽象類
  22.    {代碼以報錯處}:The type Cat must implement the inherited abstract method Animal.shout()
  23.  E.abstract關鍵字能修飾  類   方法
  24.               不能修飾 成員變量   構造方法
  25. F.抽象類中的成員  成員變量  構造方法  成員方法
  26.  {代碼以報錯處}:The abstract method shout in type Animal can only be defined by an abstract class
  27.  
  28. {代碼以報錯處}: Illegal modifier for the field name; only public, protected, private, static, final, transient & volatile are permitted
  29. {代碼以報錯處}: Illegal modifier for the constructor in type Animal; only public, protected & private are permitted

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章