1 package com.oop.demo5; 2 //在Java中, 所有的类,都默认直接或者间接继承object 3 //Person人: 父类 ctrl+H 展开继承关系树 4 public class Person { 5 //public 6 //protected 7 //default 8 //private 9 private int money = 10_0000_0000; 10 11 public void say() { 12 System.out.println("说了一句话"); 13 } 14 15 public int getMoney() { 16 return money; 17 } 18 19 public void setMoney(int money) { 20 this.money = money; 21 } 22 }
1 package com.oop.demo5; 2 //学生 is 人:派生类,子类 3 //子类继承了父类,就会拥有父类的全部方法! 4 5 public class Student extends Person { 6 7 } 8 9 package com.oop.demo5; 10 11 public class Teacher extends Person { 12 }