Q. What is the output of the below Java code with Enums and Constructors?
Code:enum Ship
{
BOAT(5), SHIP(10), VESSEL(100);
int capacity;
Ship(int i)
{
capacity = i;
}
Ship(){}
void show() {System.out.println("Capacity: " + capacity);}
}
public class EnumTest4
{
public static void main(String[] args)
{
Ship s1 = Ship.BOAT;
s1.show();
}
}
β
Correct Answer: (B)
Capacity: 5