Java--子类继承父类

package com.company;
class FL {
    //成员变量
    int x;
    int y;
    int z;

    //成员方法
    void showme ()
    {
        int result;
        result = x + y + z;
        System.out.println(+x + " " + y + " " + z);
        System.out.println(+result);
    }
}
class  ZL extends FL {

    int m;
    void showme ()
    {
        int sum;
        sum = x + y + z + m;
        System.out.println(+x + " " + y + " " + z+" "+m);
        System.out.println(+sum);

    }
}

public class Main {

    public static void main(String[] args) {
        // write your code here

        FL FL1 = new FL();
        ZL ZL1 = new ZL();
        FL1.x = 1;
        FL1.y = 2;
        FL1.z = 3;
        ZL1.x = 4;
        ZL1.y = 5;
        ZL1.z = 6;
        ZL1.m = 7;
        FL1.showme();
        ZL1.showme();
    }
}

 

posted @ 2020-12-22 00:45  zhou小月  阅读(135)  评论(0编辑  收藏  举报