题解 | #重写父类方法#

重写父类方法

http://www.nowcoder.com/practice/aec55d55435b4af69e625d7072af3fa1


public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            Sub sub = new Sub(x, y);
            System.out.println(sub.sum());
        }
    }

}

class Base {

    private int x;
    private int y;

    public Base(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public  int getY() {
        return y;
    }

    public  int sum() {
        return getX() + getY();
    }

}

class Sub extends Base {
    private int x;
    private int y;

    public Sub(int x, int y) {
        super(x, y);
        this.x=x;
        this.y=y;
    }
    
    
    public int getX() {
        return x;
    }
    
    
    public  int getY(){
        return y;
    }

    
    public  int sum() {
        return getX()*10 + getY();
    }

    //write your code here......
    

}
全部评论

相关推荐

点赞 评论 收藏
分享
小浪_Coding:1. 个人技能排版太乱, 写的技术栈太浅了, 跟测试,自动化相关的太少; 2. 项目开发类的太简单没有亮点, 算法类的项目建议只放一个,最好有自动化,CI/CD, pipline的项目, 需要更换; 3.整体排版需要优化, SOOB打招呼都需要注意等.
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务