public class Cow
{
private double weight;
public Cow(){};
public Cow(double weight)
{
this.weight=weight;
}
private class CowLeg
{
private double length;
private String color;
public CowLeg(){};
public CowLeg(double length,String color)
{
this.color=color;
this.length=length;
}
public void setLength(double length)
{
this.length=length;
}
public double getLength()
{
return this.length;
}
public void setColor(String color)
{
this.color=color;
}
public String getColor()
{
return this.color;
}
public void info()
{
System.out.println("牛腿颜色:"+color+" 高:"+length);
System.out.println("本牛腿所在奶牛重:"+weight);
}
}
public void test()
{
CowLeg cl=new CowLeg(1.12,"黑白相间");
cl.info();
}
public static void main(String[] args)
{
Cow cow=new Cow(378.9);
cow.test();
}
}
内部类 学习笔记(一)
最新推荐文章于 2022-11-19 12:58:43 发布