1、java支持单继承和多层继承。
2、子类继承了父类,会继承父类的所有一切,包括私有的private的修饰符,只是不给你访问private修饰符而以。
第一种:单继承
People 类:
public class People{
public String name;
public 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;
}
}
Student类:
public class Student extends People{
public String school;
public void setSchool(String _school){
this.school=_school;
}
public String getSchool(){
return school;
};
};
测试:MainDao类
public class MainDao {
public static void main(String ages[]){
Student s=new Student();
s.setName("时光与你");
s.setAge(1);
s.setSchool("小孩学院");
System.out.println("名字:"+s.name+"; 年龄:"+s.age+"; 学院"+s.school);
}
}