difference between Abstract class and interface in java

本文详细阐述了Java中抽象类与接口之间的主要区别,包括抽象类可以包含部分实现而接口不能,抽象类可以定义构造器及变量,而接口中的变量默认为final等。此外还介绍了Java类可以继承一个抽象类但只能实现多个接口的特点。

1. An abstract class is a class that is only partially implemented. It may contain none or multiple abstract methods. An abstract method is simply a function definition that must be implemented in a child class.

2. An interface is a fully abstract class; none of its methods are implemented.

3. Variables declared in a Java interface is by default final. An  abstract class may contain non-final variables.

4. An abstract class can have a constructor.

5. Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..

6. A Java class can implement multiple interfaces but it can extend only one abstract class.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值