继承,权限控制

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

class Student extends Person{
	private String school;
	public void setSchool(String school) {
		this.school = school;
	}
	public String getSchool() {
		return school;
	}
}
public class Test {
	public static void main(String args[]){
		Student student = new Student();
		student.setName("aike");
		student.setSchool("清华");
		System.out.println(student.getName());
		System.out.println(student.getSchool());

	}
}






default是默认的,不用写。public class ,class(不写默认default)

猜你喜欢

转载自ztao2333.iteye.com/blog/2286682