编程语言
首页 > 编程语言> > Java的继承

Java的继承

作者:互联网

Java的继承

继承

package com.cnblogs;
//本类用于实现
public class Application {
    public static void main(String[] args) {
        //实例化父类
        Persion persion = new Persion();
        //实例化子类
        Student stu = new Student();

        //子类调用父类方法
        stu.say();//说了一句话!
        //子类调用父类属性
        System.out.println(stu.money);//1000000000

        //父类静态方法的调用(不需要实例化,直接用)
        Persion.show();
        Student.show();
        //同理,父类静态属性的调用
        System.out.println(Persion.rmb);//1000000000
        System.out.println(Student.rmb);//1000000000
    }
}

package com.cnblogs;
/*
persion类
 */
public class Persion {
    //父类方法
    public void say(){
        System.out.println("说了一句话!");
    }

    //父类属性
    public int money =10_0000_0000;

    public static void show(){
        System.out.println("父类静态方法!");

    }

    public static int rmb = 10_0000_0000;
}

package com.cnblogs;
/*
student类
 */
public class Student extends Persion{

}

super

https://www.cnblogs.com/fangweicheng666/p/14978679.html

重写

https://www.cnblogs.com/fangweicheng666/p/14978773.html

标签:Java,继承,子类,println,Persion,父类,public
来源: https://www.cnblogs.com/fangweicheng666/p/14978778.html