Important Points about Abstract class
-
abstract
keyword is used to make a class abstract.---abstract关键字是一个类是否抽象的标志。 - Abstract class can’t be instantiated.---抽象类不能实例化。
- We can use
abstract
keyword to create an abstract method, an abstract method doesn't have body.---抽象方法只能有声明,不能有内容。 - If a class have abstract methods, then the class also needs to be made abstract using abstract keyword, else it will not compile.---如果一个类中有抽象方法,那这个类必定是抽象的,即类必须有abstract关键字来修饰,不然无法通过编译。
- Its not necessary to have abstract classes to have abstract method.---一个抽象类中不一定必须有抽象方法。
- If abstract class doesn't have any method implementation, its better to use interface because java doesn't support multiple class inheritance.---如果一个抽象类中没有任何的方法的实现,那不是很有必要使用抽象类,我们可以使用interface去替代(因为interface中的所有方法都是abstract的,只是abstract省略而已),因为java不支持多重继承,但是java可以通过多重实现接口来变相实现多重继承。
- The subclass of abstract class must implement all the abstract methods unless the subclass is also an abstract class.---子类必须实现抽象父类中所有抽象的方法,不然编译无法通过,除非子类依旧是一个抽象类。
- All the methods in an interface are implicitly abstract.---interface中的所有方法都是abstract的
- Abstract classes can implement interfaces without even providing the implementation of interface methods.---?
- Abstract classes are used to provide common method implementation to all the subclasses or to provide default implementation.---抽象类为所有子类提供了公共的方法实现。
- We can run abstract class like any other class if it has
main()
method.