C++ 造的坑 Java 来补,补坑的路上 Java 接口怎么写?
public interface JInterface {public abstract void mthod1();}public class JClass implements JInterface {@Overridepublic void mthod1() {}}
public interface J8Interface1 { public default void methodDefault() { System.out.println("This is J8Interface1 default method!"); } void mthod1();}public interface J8Interface2 { public default void methodDefault() { System.out.println("This is J8Interface2 default method!"); } void mthod1();}public class JClass implements J8Interface1,J8Interface2 {@Overridepublic void mthod1() { System.out.println("Override in the Subclass");}@Overridepublic void methodDefault() {// J8Interface1的调用J8Interface1.super.methodDefault();// J8Interface2的调用J8Interface2.super.methodDefault();}public static void main(String[] args) {// TODO Auto-generated method stubJ8Interface1 j81= new JClass();j81.mthod1();j81.methodDefault();J8Interface2 j82= new JClass();j82.mthod1();}}
Override in the Subclass
This is J8Interface1 default method!
This is J8Interface2 default method!
Override in the Subclass
public interface J9Interface {
public default void methodDefault() {
System.out.println("This is J8Interface2 default method!");
this.methodPrivate();
methodStatic();
}
void mthod1();
public static void methodStatic() {
System.out.println("This is J9Interface9 static method!");
}
private void methodPrivate() {
System.out.println("This is J9Interface9 private method!");
}
}
关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/
关注网络尖刀微信公众号
随时掌握互联网精彩
随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 总书记这样指导旅游强国建设 4968658
- 2 警方通报胖猫事件:女方不构成诈骗 4938710
- 3 专家称要支持60-70岁老年人就业需求 4820304
- 4 科技赋能 共享美好 4759688
- 5 央媒评“指豚为鱼”:何其讽刺 4642335
- 6 为什么520这么多学生请病假? 4536819
- 7 中国选手一眨眼的功夫就夺冠了 4435469
- 8 英国年度最性感男人 4302016
- 9 河南网友山中发现日寇坟墓? 4236950
- 10 今年荔枝有的吃就不错了 4174335