title: Cannot understand enums in java
body: <p>I was looking at an example code provided in my book  </p>
  
  <pre><code>enum Coin
  {
     PENNY(1),
     NICKEL(5),
     DIME(10),
     QUARTER(25);
  
     private final int denomValue;
  
     Coin(int denomValue)
     {
        this.denomValue = denomValue;
     }
  
     int denomValue()
     {
        return denomValue;
     }
  
     int toDenomination(int numPennies)
     {
        return numPennies / denomValue;
     }
  }
  
  public class Coins
  {
     public static void main(String[] args)
     {
        if (args.length == 1)
        {
           int numPennies = Integer.parseInt(args[0]);
           System.out.println(numPennies + " pennies is equivalent to:");
           int numQuarters = Coin.QUARTER.toDenomination(numPennies);
           System.out.println(numQuarters + " " + Coin.QUARTER.toString() +
                              (numQuarters != 1 ? "s," : ","));
           numPennies -= numQuarters * Coin.QUARTER.denomValue();
           int numDimes = Coin.DIME.toDenomination(numPennies);
           System.out.println(numDimes + " " + Coin.DIME.toString() +
                              (numDimes != 1 ? "s, " : ","));
           numPennies -= numDimes * Coin.DIME.denomValue();
           int numNickels = Coin.NICKEL.toDenomination(numPennies);
           System.out.println(numNickels + " " + Coin.NICKEL.toString() +
                              (numNickels != 1 ? "s, " : ", and"));
           numPennies -= numNickels*Coin.NICKEL.denomValue();
           System.out.println(numPennies + " " + Coin.PENNY.toString() +
                              (numPennies != 1 ? "s" : ""));
        }
        System.out.println();
        System.out.println("Denomination values:");
        for (int i = 0; i &lt; Coin.values().length; i++)
           System.out.println(Coin.values()[i].denomValue());
     }
  }  
  </code></pre>
  
  <p>If enum is like a class, is it possible to have the same name for a method and field inside a class, as it has been done here with denomValue?  </p>
  
  <p>Why is it calling <code>int numQuarters = Coin.QUARTER.toDenomination(numPennies);</code> in this manner? Is <code>toDenomination()</code> static by default?  </p>
  
  <p>In the above case, what is the value of denomValue field? The output for this program hints that it should be equal to QUARTER. But how does that work? Is Coin.QUARTER equivalent to creating a coin object and passing QUARTER as it's constructor argument?</p>