1,新建Application类,作为程序的入口
package demo05;
//继承
public class Application {
public static void main(String[] args) {
Student s1 = new Student();
s1.say(); //说了一句话!!
// System.out.println(s1.money);//1000000000 加了私有 修饰后,这个语句报错
System.out.println("s1.getMoney():"+s1.getMoney()); //s1.getMoney():1000000000
}
}
2,新建Person类
package demo05;
/*
继承
*/
public class Person {
public void say(){
System.out.println("说了一句话!!");
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
private int money=10_0000_0000;
/*
public 公共的
private 私有的
default 默认的
protected 受保护的
*/
}
3,新建Student类
package demo05;
public class Student extends Person {
}
4,新建Teacher类
package demo05;
public class Teacher extends Person{
}
5,生成树
6,运行结果