面向对象09什么是继承
package com.oop;
import com.oop.demo05.Student;
public class Application {
public static void main(String[] args) {
Student student = new Student();
student.say();
student.setMoney(100000000);
System.out.println(student.getMoney());
}
package com.oop.demo05;
//Person 人 : 父类
//在Java中,默认都继承object类
public class Person {
//public
//protected 受保护的
//private 无法继承
//default 默认的
private int money = 10_0000_0000;
public void say(){
System.out.println("说了一句话");
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
}
}
package com.oop.demo05;
//学生 is 人 :派生类、子类
//子类继承了父类,就会拥有父类的全部方法!
public class Student extends Person{
}
package com.oop.demo05;
//Teacher is 人:派生类、子类
public class Teacher extends Person{
}