java例程练习(关于重写[overwrite/override])

public class Test {
	public static void main(String[] args) {
		Student student = new Student();
		Person person = new Person();
		
		person.setName("Tom");
		person.setAge(18);
		
		student.setName("John");
		student.setAge(19);
		student.setSchool("AHU");
		
		System.out.println(person.getInfo());
		System.out.println(student.getInfo());
		
	}
}


class Person {
	private String name;
	private int age;
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getAge() {
		return age;
	}
	
	public String getInfo() {
		return "Name: " + getName() + "\n" + "Age: " + getAge();
	}	
}

class Student extends Person {
	private String school;

	public void setSchool(String school) {
		this.school = school;
	}

	public String getSchool() {
		return school;
	}
	
	public String getInfo() {
		return "Name: " + getName() + "\n" + "Age: " + getAge()
			+ "\nSchool: " + getSchool();
	}
}








你可能感兴趣的:(java,String,Class)