关于覆盖和隐藏的问题

scuthdd scuthdd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public class planet{
public static void hide(){
System.out.println("The hide method in Planet.");
}
public void override(){
System.out.println("The override method in Planet.");
}
}

public class earth extends planet{
public static void hide(){
System.out.println("The hide method in Earth.");
}
public void override(){
System.out.println("The override method in Earth.");
}
pubilc ststic void main (String[] args){
Earth myEarth=new Earth();
Planet myPlanet=(Planet)myEarth;
myPlanet.hide();
myPlanet.override();
}
}


输出
the hide method in Planet.
The override method in Earth.

是怎么得来的,哪一句是控制输出的?

myPlanet.hide();
myPlanet.override();
这两句能说说什么意思嘛?
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
scuthdd
Java SE 62,621 成员 307,251 内容