Create an account to track your scores
and create your own practice tests:
Test: Computer Science
Consider the following code:
public static interface Shape2D {
public double getArea();
}
public static class Ellipse implements Shape2D {
private double r1,r2;
public Ellipse(double r1,double r2) {
this.r1 = r1;
this.r2 = r2;
}
public double getArea() {
return Math.PI * r1 * r2;
}
}
public static class Circle extends Ellipse {
private double radius;
public Circle(double r) {
super(r,r);
}
public double getArea() {
return super.getArea();
}
public double getCircumference() {
return Math.PI * 2 * radius;
}
}
public static void main(String[] args) {
Shape2D[] vals = {new Circle(5),new Ellipse(8,5)};
for(int i = 0; i < vals.length; i++) {
System.out.println("Area " + (i+1) + ": " + vals[i].getArea());
}
}
1. | What is the output for this code? |
Area 1: 31.41592653589793
Area 2: 201.061929829746752
Area 1: 78.53981633974483
Area 2: 78.53981633974483
The code will not compile.
Area 0: 78.53981633974483
Area 1: 201.061929829746752
Area 1: 78.53981633974483
Area 2: 125.66370614359172
