题解 | #重写父类方法#

重写父类方法

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

import java.util.Scanner;

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 final int getY() {
        return y;
    }

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

}

class Sub extends Base {

    public Sub(int x, int y) {
        super(x, y);
    }

    //write your code here......
    public int getX() {
        return super.getX() * 10;
    }

}

全部评论

相关推荐

今天刚抽空做了测试题目也太多了
投递武汉楚兴技术有限公司等公司7个岗位
点赞 评论 收藏
分享
程序员牛肉:不用想,肯定是被卡学历了。 简历其实没什么大问题,就中规中矩的及格简历。但问题就在于有太多学历比你好的人了。所以即使你们的能力一样,人家也更加倾向于约面学历更好的。
实习,投递多份简历没人回...
点赞 评论 收藏
分享
07-15 00:33
江苏大学 Java
代码飞升:哈哈哈哈评论区三个打广告的
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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