Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java 面试题 抽象类与接口的区别 答案描述不够完整 #23

Open
2020779477 opened this issue Sep 21, 2022 · 0 comments
Open

Comments

@2020779477
Copy link

相同点:1.都可以拥有抽象方法 2.都不能实例化
不同点:1.接口需要实现类用implements关键字实现,并且支持接口与接口的多继承,类与接口的多实现。抽象类需要子类用extend关键
字继承,只支持单继承。
2.接口只可以有常量,默认是public final static修饰。抽象类既可以有普通变量,也可以有常量。
3.接口jdk1.8支持了默认方法和静态方法,1.9支持了私有方法,其余都是抽象方法。抽象类可以有任意的方法。
4.接口没有构造器,抽象类有构造器但是不能实例化,只是为了供给子类创建对象使用。
5.接口不能有初始代码块,抽象类可以。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant