Which four are true about enums?

Which four are true about enums?

Which four are true about enums?

A.
An enum is typesafe.

B.
An enum cannot have public methods or fields.

C.
An enum can declare a private constructor.

D.
All enums implicitly implement Comparable.

E.
An enumcan subclass another enum.

F.
An enum can implement an interface.

Explanation:
C:The constructor for an enum type must be package-private or private access.

Reference: Java Tutorials,Enum Types



Leave a Reply 3

Your email address will not be published. Required fields are marked *


wojtek

wojtek

C F are TRUE

D. – NO !!!
All enums implicitly implement Comparable -> not true
Enums are sorted by default in order of their declariation, not by natural order

robkam

robkam

Really? So check it:

public class TestClass
{
private enum Q { A, B, C, D }

public static void main(String [] args) throws Exception
{
Comparable x = Q.A;
System.out.println(x);
}
}