对象-继承

继承

课堂截图

picture1

代码

父类

package com.oop.demo04;

//在Java中,所有的类,都默认直接或间接继承Object类
//人 : 父类
public class Person {
    
    //public
    //protected
    //default
    //private
    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;
    }
}

子类

package com.oop.demo04;

//Stduent is Person   子类
//子类继承了父类,就会拥有父类的全部方法
public class Student extends Person {
    
}

应用

package com.oop;

import com.oop.demo04.Student;

public class Application {
    public static void main(String[] args) {
        Student student = new Student();
        student.say();
        System.out.println(student.getMoney());
    }
}


Super用法

课堂截图

picture1 picture1

重写

课堂截图

picture1
posted @ 2021-12-26 12:55  梧桐灯下江楚滢  阅读(16)  评论(0编辑  收藏  举报