继承

继承


```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{


}
```

posted @ 2021-07-26 14:08  子时未临  阅读(9)  评论(0编辑  收藏  举报