Java abstract method understanding

Abstract method: For
example:
1. A method for calculating the area of ​​a two-dimensional figure. A concrete figure can be calculated, but what about it? This method is an abstract method.
2. The way animals eat, cats eat fish, dogs eat bones, but if you ask what animals eat? Can't say, so abstract method.

如果父类当中的方法不确定如何进行方法体实现,那这样的方法就是一个抽象方法。

 * 抽象方法 加abstract关键字 去掉大括号  直接分号
 * 抽象类:抽象方法所在的类必须是抽象类
 * 如何使用抽象类 抽象方法
 * 1.不能直接创建抽象对象(创建一个动物?不具体)
 * 2.必须新建一个类去继承
 * 3.子类必须覆盖重写抽象父类中所有的抽象方法
 * 4.创建子类对象进行使用
 * 注意事项:
 * 1.抽象类可以有构造方法
 * 2.要想访问抽象类中的方法用super来实现
 * 3.抽象类中不一定中有抽象方法,但是有抽象方法一定是抽象类
 * 4.抽象类的子类必须覆盖重写抽象父类中所有的抽象方法,否则你子类也是一个抽象类

Guess you like

Origin blog.csdn.net/weixin_45663946/article/details/109038172