JAVA子类和父类在同一个包中,子类和父类在同一个包中继承性
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
請問在同一個包中和在同一個源文件有什么區(qū)別??????
以下子類和父類在同一個源文件中,如何保存為在同一個包中?
class Father
{ private int money;
int weight;
int getWeight()
{
return weight ;
}
protected void setWeight(int w)
{
weight=w;
}
}
class Son extends Father
{ String hand ;
public void setHand(String hand)
{
this.hand=hand;
}
String getHand()
{
return hand;
}
}
class Grandson extends Son
{ String foot ;
public void setFoot(String foot)
{
this.foot=foot;
}
String getFoot()
{
return foot;
}
}
public class Example5_1
{ public static void main(String
args[])
{
Son son=new Son();
Grandson grandson=new
Grandson();
son.setWeight(67);
son.setHand("一雙大手");
grandson.setWeight(25);
grandson.setHand("一雙小手");
grandson.setFoot("一雙小腳");
System.out.println("兒子重量:"+son.getWeight());
System.out.println("孫子重量:"+grandson.getWeight());
System.out.println("兒子的手:"+son.getHand());
System.out.println("孫子的手:"+grandson.getHand());
System.out.println("孫子的腳:"+grandson.getFoot());
}
}
總結
以上是生活随笔為你收集整理的JAVA子类和父类在同一个包中,子类和父类在同一个包中继承性的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: php总是报错,php - 简单工厂模式
- 下一篇: 创造 10 万个就业岗位,苹果成为印度电
