现在的位置: 首页 > 综合 > 正文

内部类 学习笔记(一)

2016年11月05日 ⁄ 综合 ⁄ 共 665字 ⁄ 字号 评论关闭
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();
	}
}

抱歉!评论已关闭.