vendredi 29 mai 2015

Does main method work differently in enums and classes?

In the following code :

enum Rank {
FIRST(20), SECOND(0), THIRD(8);
Rank(int value) {
System.out.print(value);
} 
}
public static void main (String[] args) {
}

This gives the following output: 2008 If however the main method is declared in some other class like this:

class XYZ
{
public static void main (String[] args) {

}

There is no output. What is the difference between main in enum and main in the class?

Aucun commentaire:

Enregistrer un commentaire