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

接口和抽象类的区别是什么 #146

Closed
raoyh opened this issue Feb 17, 2019 · 3 comments
Closed

接口和抽象类的区别是什么 #146

raoyh opened this issue Feb 17, 2019 · 3 comments
Labels

Comments

@raoyh
Copy link

@raoyh raoyh commented Feb 17, 2019

在JDK8中,接口也可以定义静态方法,可以直接用接口名调用。实现类和实现是不可以调用的。
如果同时实现两个接口,接口中定义了一样的默认方法,必须重写,不然会报错

@Snailclimb

This comment has been minimized.

Copy link
Owner

@Snailclimb Snailclimb commented Feb 21, 2019

感谢您的回答!

@lanmeiniu

This comment has been minimized.

Copy link

@lanmeiniu lanmeiniu commented May 31, 2019

关于抽象类
JDK 1.8以前,抽象类的方法默认访问权限为protected
JDK 1.8时,抽象类的方法默认访问权限变为default
关于接口
JDK 1.8以前,接口中的方法必须是public的
JDK 1.8时,接口中的方法可以是public的,也可以是default的
JDK 1.9时,接口中的方法可以是private的

@powerLeePlus

This comment has been minimized.

Copy link

@powerLeePlus powerLeePlus commented Sep 17, 2019

jdk1.8后,接口方法可以有方法体,需要用default或static修饰。实现类无需重新。当然default方法重写也是可以的。如果一个类实现多个接口,多个接口有相同default方法,则子类必须重写该方法

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.