继承

继承

package com.andy.base.oop.demo01.demo05;

//学生 is 人  : 派生类,子类
//子类继承了父类,就会拥有父类的全部方法!
public class Student extends Person{

    //ctrl + h


}

package com.andy.base.oop.demo01.demo05;

//在java中,所有的类,都默认直接或间接继承object
// Person 人 : 父类
public class Person {

    private  int money = 10_0000_0000;
    public  void say(){
        System.out.println("说了一句话");
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }
}
/*
 public static void main(String[] args) {

        Student student = new Student();
        student.say();


    }
 */
package com.andy.base.oop.demo01;


import com.andy.base.oop.demo01.demo05.Student;

public class Application {
    public static void main(String[] args) {

        Student student = new Student();
        student.say();


    }
}

posted @ 2023-02-27 23:37  努力学习的J1an-JIan  阅读(20)  评论(0)    收藏  举报