什么是继承
作者:互联网
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 }
标签:Person,继承,money,什么,int,oop,demo5,public 来源: https://www.cnblogs.com/summerday0903/p/14409109.html