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
πŸ’¬ Discuss
βœ… Correct Answer: (B) Capacity: 5

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
289
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Ram Sharma
Publisher
πŸ“ˆ
83%
Success Rate