//People类的定义——父类
package ch06_04;
public class People {
	private String name;//私有属性，只能在本类中访问
	protected int age;  //保护属性，在本类及其子类中可以直接访问
	public People() {
		System.out.println("类People的无参构造方法调用！");
	}
    //由于属性name是私有属性，为了在其他类中对该属性访问，提供公共方法
	public String getName() { 
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public People(String name, int age) {
		this.name = name;
		this.age = age;
		System.out.println("类People的带参构造方法调用！");
	}
	public void show(){
		System.out.println( "人员信息：姓名="+name+"  年龄="+age);
	}
}
//继承People类创建的子类Student
package ch06_04;
public class Student extends People {
	private String school;
	public Student() {
		super();
		System.out.println("类Student的无参构造方法调用！");
	}
	public Student(String name, int age, String school) {
		super(name, age);
		this.school = school;
		System.out.println("类Student的有参构造方法调用！");
	}
	public void show(){//对父类方法的重写
		String out="姓名="+ getName()  +"  年龄="+  age  +"  学校="+school;
		System.out.println("学生信息："+out);
	}
	public void show2(){//子类新添的方法。
		String out="姓名="+ getName()  +"  年龄="+  age  +"  学校="+school;
		System.out.println("学生信息："+out);
	}
}
//主类，在该类中分别创建两个People对象p1、p2和两个Student对象s1、s2
package ch06_04;
public class TestMain {
	public static void main(String[] args) {
		System.out.println("人员对象的创建与显示：");
		People p1 = new People();
		People p2 = new People("李四", 25);
		p1.show();
		p2.show();
		System.out.println("学生对象的创建与显示：");
		Student s1 = new Student();
		Student s2 = new Student("张三", 20, "北大");	
		s1.show();
		s2.show();
	}
}
