题解 | #重写父类方法#

重写父类方法

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......
    

}
全部评论

相关推荐

09-28 22:01
已编辑
广西科技大学 IT技术支持
合适才能收到offe...:找桌面运维?
点赞 评论 收藏
分享
09-08 17:17
同济大学 Java
狗不理fe:里面的人劝一句,别来虾,我们部门24校招生淘汰率30%,还有一些人说有一年保护期,不可能!!!
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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