代码结构
package com.wuming.oop2.demo05; //person 人 父类 public class Person {//继承:java只有单继承,没有多继承,extends修饰public int money=10_0000_0000;private int money1=20;public int getMoney1() {return money1;}public void setMoney1(int money1) {this.money1 = money1;}public void say(){System.out.println("说了一句话");}// String看源码//Object }
package com.wuming.oop2.demo05; //学生 is 人 子类 public class Student extends Person{}
package com.wuming.oop2.demo05; //Teacher is 人 子类 public class Teacher extends Person{}
package com.wuming.oop2;import com.wuming.oop2.demo05.Person; import com.wuming.oop2.demo05.Student;public class Application {public static void main(String[] args) {Student student = new Student();student.say();System.out.println(student.money);// System.out.println(student.money1);//Error:(11, 35) java: money1可以在com.wuming.oop2.demo05.Person中访问privateSystem.out.println(student.getMoney1());//Person给私有money1添加getter后可调用Person person = new Person();person.hashCode();//在java中所有的类都默认继承Object类} }
说了一句话
1000000000
20