I wrote a test class, and I tried an enum type:
public class EnumTest { enum Car{MERCEDEZ, FERRARI}; public static void main(String[] args) { Car carObj; carObj.run(); } }
So it seems that I can “declare” the class using enum (because I don't have the Car class in my package), and I put the run() method to find out what happens. After that, I wrote the body of run() , as the IDE advised me, but inside the rename too.
enum Car { MERCEDEZ, FERRARI; public void run() { } };
I think this is very strange, but good. I continued the experiment with Frankenstein and tried to initialize the object with the constructor on the main one.
enum Car { MERCEDEZ, FERRARI; public void run() {
Car carObj = new Car();
And he says that I cannot create an instance of type EnumTest.Car, so my test is finished, but with doubt. Sorry if this seems silly, but I did not find it in my search.
Question: Why can I use the Car 'like' class, but I can not initialize it?
source share