Enums in Java

We ca define a enum in any of our classes like this

    public enum BodyTypes{
        STAR,
        PLANET,
        DWARF_PLANET,
        MOON,
        COMET,
        ASTEROID
    }

And in the same class we can define a constructor that takes enum BodyType as an argument

    public HeavenlyBody(String name, double orbitalPeriod,BodyTypes bodyType) {
            this.key = new Key(name,bodyType);
            this.orbitalPeriod = orbitalPeriod;
            this.satellites = new HashSet<>();
        }

And we can make an object of this HeavenlyBody class we need to provide the actual value for the enum BodyType like below

   HeavenlyBody earth = new HeavenlyBody(name, orbitalPeriod,BodyTypes.PLANET);

Another thing to note is for enums its compile time checking that is if we pass anything like this to the constructor an error will be thrown becuse PLANETTTTTTTTTTttt is not there in enum BodyTpes.

  HeavenlyBody earth = new HeavenlyBody(name, orbitalPeriod,BodyTypes.PLANETTTTTTTTTTttt);