父类Base中定义了若干get方法,以及一个sum方法,sum方法是对一组数字的求和。请在子类 Sub 中重写 getX() 方法,使得 sum 方法返回结果为 x*10+y
输入描述:
整数
输出描述:
整数的和
示例1
输入
1 2
输出
12
加载中...
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...... }
1 2
12