快捷键:crl+h可以看到该类下的父子继承关系
父亲:人
package oop.Demon5;
//Person 人 父亲
public class Person {
// public
//protected
//default
// private
public int money = 10000;
public void say(){
System.out.println("说了一句话");
}
//在java中,所有的类都直接或者间接默认继承object
}
儿子区块:老师与学生
package oop.Demon5;
//学生
public class Student extends Person {
//crl+h快捷键
}
package oop.Demon5;
public class Teacher extends Person {
}
应用:
package oop;
import oop.Demon5.Student;
public class Application {
public static void main(String[] args) {
Student student = new Student();
student.say();
System.out.println(student.money);
}
}
网友评论