← Quiz: Java Enums: all 10 questions
Quiz: Java Enums · Question 8 of 10
What does this print? (code)
What does this print?
enum Shape {
SQUARE { double area(double s) { return s * s; } },
CIRCLE { double area(double r) { return 3 * r * r; } };
abstract double area(double x);
}
public class Main {
public static void main(String[] args) {
System.out.println(Shape.SQUARE.area(2) + Shape.CIRCLE.area(2));
}
}
- A.8.0
- B.16.0
- C.4.012.0
- D.Compile error
Answer & explanation
Correct answer: 16.0
Each constant runs its own area: 4.0 + 12.0 = 16.0 (numbers add, no string here).
Can you get the rest right without peeking?
Take the timed Quiz: Java Enums quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →