题解 | #重写父类方法#

重写父类方法

http://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......
@Override
public int getX(){
    return (super.getX())*10;
}

}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:20
点赞 评论 收藏
分享
程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 11:20
点赞 评论 收藏
分享
评论
6
1
分享

创作者周榜

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