Computer Science › Interface Declarations
Why is the "default" keyword used in a switch statement?
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());
}
}
What is the output for this code?
Which of the following declares an interface to be used for anything that can implement the actions of a sink?
Which of the following represents a valid declaration of an interface and a class that implements that interface?
Which of the following represents an acceptable definition of an interface?
Design an interface Cat. The interface must include the functions meow, purr, clean, hungry, isPurring, isClean, isSleeping, and isHungry.