继承
继承
```java
package com.zishi.oop.demo05;
public class Application {
public static void main(String[] args) {
Student student = new Student();
student.say();
}
}
```
```java
package com.zishi.oop.demo05;
//在Java中,所有的类,都默认直接或者间接继承Object
//CTRL + H 查看
//父类 (基类)
public class Person {
//public
//protected
//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;
}
}
```
```java
package com.zishi.oop.demo05;
//子类 (派生类)
public class Student extends Person{
}
```
```java
package com.zishi.oop.demo05;
public class Teacher extends Person {
}
```
```java
package com.zishi.oop.demo05;
//子类 (派生类)
public class Student extends Person{
}
```