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 农文旅融合绘就美丽乡村新图景 7915558
- 2 人形机器人牵绳遛机器狗 7912074
- 3 航班故障返回西安 旅客:发动机起火 7882018
- 4 春回大地农事起 春耕备耕正当时 7749768
- 5 《哪吒2》票房破135亿 7667858
- 6 女儿遭家暴失明母亲自责让其闪婚 7546669
- 7 文科生出身的他将成美军“一把手” 7434942
- 8 湖南严禁用AI生成医疗处方 7391517
- 9 美女网红救人溺亡 母亲又遭车祸 7205886
- 10 欧洲多国领导人:俄乌和谈不能缺乌欧 7127564