Important Points about abstract class in Java

参考

abstract特征修饰符的作用
Abstract Class in Java.


Important Points about abstract class in Java

  1. abstract keyword is used to create an abstract class in java.

  2. Abstract class in java can’t be instantiated.

  3. Abstract class have constructors.

  4. We can use abstract keyword to create an abstract method, an abstract method doesn’t have body.

  5. If a class have abstract methods, then the class should also be abstract using abstract keyword, else it will not compile.

  6. It’s not necessary for an abstract class to have abstract method. We can mark a class as abstract even if it doesn’t declare any abstract methods.

  7. If abstract class doesn’t have any method implementation, its better to use interface because java doesn’t support multiple class inheritance.

  8. The subclass of abstract class in java must implement all the abstract methods unless the subclass is also an abstract class.

  9. Java Abstract class can implement interfaces without even providing the implementation of interface methods.

  10. Java Abstract class is used to provide common method implementation to all the subclasses or to provide default implementation.

  11. We can run abstract class in java like any other class if it has main() method.

你可能感兴趣的:(基础知识,java,jvm,开发语言)