JAVA小练习53——super 关键字

class Fu{
	
	int x = 10;

	String name;

	public Fu(String name){
		this.name = name;
		System.out.println("父类带参的构造函数....");
	}

	public Fu(){
		System.out.println("父类无参的构造函数....");
	}


	public void eat(){
		System.out.println("小头爸爸吃番薯...");
	}
}


class Zi extends Fu{
	int x = 20;
		
	public Zi(String name){
		super(name); //调用父类一个参数的构造函数...
		
		System.out.println("子类带参构造函数....");

		//super();  //调用了父类无参的构造函数....
	}

	public Zi(){
		System.out.println("子类无参构造函数....");
	}

	public void print(){
		super.eat();
		System.out.println("x:"+super.x);  
	}

	public void eat(){
		System.out.println("大头儿子吃龙虾...");
	}

}


class Demo53 
{
	public static void main(String[] args) 
	{		

		Zi zi = new Zi("大头儿子");
		System.out.println("名字:"+ zi.name);
		Zi zii = new Zi();
		System.out.println("名字:"+ zii.name);
		
		zi.eat();
		zi.print();

	}
}

你可能感兴趣的:(JAVA小练习53——super 关键字)