One exception that it (the constructor) is always private.
Not always private. A constructor inside an enum CAN ALSO take default access specifier, i.e. leaving out any access specifier immediately before the constructor inside an enum is the same as the constructor having the default access specifier.
In an enum declaration, a constructor declaration with no access modifiers is private.
In an enum declaration with no constructor declarations, a default constructor is implicitly declared. The default constructor is private, has no formal parameters, and has no throws clause.
If you like our products and services, please help us by posting your review here.
frodank wrote:Isn't this one correct?
System.out.println(MR.format("Rob", "Miller"));
You don't have to write "Title." before the enum-value if you do a static import on MR.
It is possible but not in this case. Both, Title and TestClass are being defined in the same file. There is no package statement. So how will you import Title statically?
If you like our products and services, please help us by posting your review here.
The problem statement says that Title is accessible where required. So that means Title is imported. Therefore, you have to use Title.MR instead of simply using MR.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.