注意:此页面搜索的是所有试题
题目内容
(国家开放大学面向对象程序设计)
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(5,8);
y=new Triangle(5,8);
System.out.println(x.area()+", "+y.area());
}
}
【A.】40.0, 20.0
【B.】80.0, 40.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(5,8);
y=new Triangle(5,8);
System.out.println(x.area()+", "+y.area());
}
}
【A.】40.0, 20.0
【B.】80.0, 40.0
参考答案