A
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();
}
}
{
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 - Option(B)
- Views: 21
- Filed under category Java
- Hashtags:
Discusssion
Login to discuss.