注意:此页面搜索的是所有试题
题目内容
(国家开放大学面向对象程序设计)
abstract class Shape {
int a,b;
public Shape(int aa, int bb) {a=aa; b=bb;}
abstract public double area();
}
class Rectangle extends Shape {
public Rectangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b;}
}
class Triangle extends Shape {
public Triangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b/2;}
}
public class XXK3 {
public static void main(String[] args) {
Shape x,y;
x=new Rectangle(10,20);
y=new Triangle(10,15);
System.out.println(x.area()+", "+y.area());
}
}
【A.】200.0, 75.0
【B.】400.0, 150.0
int a,b;
public Shape(int aa, int bb) {a=aa; b=bb;}
abstract public double area();
}
class Rectangle extends Shape {
public Rectangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b;}
}
class Triangle extends Shape {
public Triangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b/2;}
}
public class XXK3 {
public static void main(String[] args) {
Shape x,y;
x=new Rectangle(10,20);
y=new Triangle(10,15);
System.out.println(x.area()+", "+y.area());
}
}
【A.】200.0, 75.0
【B.】400.0, 150.0
参考答案