Important Points about abstract class in Java

Java中的abstract关键字用于创建抽象类,抽象类可以有构造器但不能实例化。如果包含抽象方法,类必须声明为抽象类。抽象类可以实现接口,但不必提供接口方法的实现。子类必须实现抽象类的所有抽象方法,除非子类也是抽象类。抽象类常用于为子类提供公共方法实现或默认实现。
摘要由CSDN通过智能技术生成

Important Points about abstract class in Java

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

  1. Abstract class have constructors.
  2. We can run abstract class in java like any other class if it has main() method.
  3. Abstract class in java can’t be instantiated.
  4. If abstract class doesn’t have any method implementation, its better to use interface because java doesn’t support multiple class inheritance.

  1. We can use abstract keyword to create an abstract method, an abstract method doesn’t have body.
  2. 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.
  3. If a class have abstract methods, then the class should also be abstract using abstract keyword, else it will not compile.

  1. Java Abstract class can implement interfaces without even providing the implementation of interface methods.
  2. The subclass of abstract class in java must implement all the abstract methods unless the subclass is also an abstract class.

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

参考

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值