- 面向对象的三个特征:继承,封装,多态
- 什么是继承?
- 一个类得到了另外一个类当中的成员方法和成员变量
- Jvava当中支持单继承
classPerson{
String name;
int age;
void eat(){
System.out.println("吃饭");
}
void introduce(){
System.out.println("我的名字是"+ name +",我的年龄是"+ age);
}
}
classStudent extends Person{
int grade;
void study(){
System.out.println("学习");
}
}
classTeacher extends Person{
}
classTest{
publicstaticvoid main(String args []){
Student student =newStudent();
student.name ="张三";
student.age =20;
student.grade =3;
student.eat();
student.introduce();
student.study();
}
}
转载于:https://www.cnblogs.com/arroneve/p/5815431.html