Java 面向对象 之 继承的限制

http://www.verejava.com/?id=16992794557845

/**
3. 继承的限制
			java 不运行多继承, 也就是只能继承一个类, 但是其父类可以再继承一个类
			继承具有传递性
*/
public class Inheritence2
{
	public static void main(String[] args)
	{
		//生出一个儿子
		Child son=new Child();
	}
}
class ChinesePeople
{
	public ChinesePeople()
	{
		System.out.println("实例化中国人种");
	}
}
class Father extends ChinesePeople
{
	public Father()
	{
		System.out.println("实例化父亲");
	}
}
class AmericaPeople
{
	public AmericaPeople()
	{
		System.out.println("实例化一个美国人种");
	}
}
class Mother extends AmericaPeople
{
	public Mother()
	{
		System.out.println("实例化妈妈");
	}
}
class Child extends Mother
{
	public Child()
	{
		System.out.println("实例化儿子");
	}
}

http://www.verejava.com/?id=16992794557845

猜你喜欢

转载自blog.csdn.net/verejava/article/details/80520261