A

Admin • 830.13K Points
Coach

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();
}
}
  • (A) Capacity: 0
  • (B) Capacity: 5
  • (C) Capacity: 10
  • (D) Capacity: 100
  • Correct Answer - Option(B)
  • Views: 21
  • Filed under category Java
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.