- 动物类
- 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
抽象
最新推荐文章于 2022-10-21 15:16:47 发布