当前位置:网站首页>Abstract methods and abstract classes

Abstract methods and abstract classes

2022-06-12 22:56:00 I met you too

Abstract methods and abstract classes

Abstract method : That is to add abstract keyword , Then remove the braces , End of semicolon .
abstract class : The class of the abstract method is the abstract class . stay class Write before abstract that will do . Abstract class cannot create object , If the build fails , Only objects with non Abstract subclasses can be created .
There can be construction methods in abstract classes , Is used by subclasses to create objects , Initializes the . Subclass construction method , There is a default super(); You need to access the constructor of the parent class
Abstract classes don't necessarily contain abstract methods , But a class with an abstract method must be an abstract class .
Subclasses of abstract classes must override all abstract methods in the abstract parent class , Otherwise, the compilation fails and an error is reported , Unless the subclass is also an abstract class .
How to use abstract classes and abstract methods :
1、 You can't create... Directly new An abstract class object .
2、 You must inherit the abstract parent class with a subclass .
3、 Subclasses must override all abstract methods in the overriding Abstract parent class .
When overriding , Subclasses remove the of abstract methods abstract keyword , Add braces to write the content .
4、 Create subclass objects for use .

原网站

版权声明
本文为[I met you too]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202281120578881.html