title: How to make field in abstract class common in inner classes without making static?
body: <p>Suppose I have the following abstract class with nested static classes:</p>
  <pre class="lang-java prettyprint-override"><code>/**
   * Command class.
   */
  public abstract class Command {
      public String commandName; // The name of the command.
  
      private Command() {}
  
      /**
       * Help command.
       */
      public static final class Help extends Command {
          public Help() { this.commandName = &quot;help&quot;; }
      }
  
      /**
       * Selection command.
       */
      public static final class Select extends Command {
          public final int choice;
          public Select(int choice) {
              this.commandName = &quot;select&quot;;
              this.choice = choice;
          }
      }
  }
  
  </code></pre>
  <p>I want the ability to access the field <code>commandName</code> from the <code>Help</code> and <code>Select</code> classes through <code>Command.Help.commandName</code>, for example. Unfortunately I can't seem to do this because the commandName field is not static. Let's say I &quot;fix&quot; this issue by making <code>commandName</code> static. The next problem arises when I run the following block of code:</p>
  <pre class="lang-java prettyprint-override"><code>Command c1 = new Command.Help();
  System.out.println(Command.Help.commandName);
  Command c2 = new Command.Select();
  System.out.println(Command.Help.commandName);
  </code></pre>
  <p>This block outputs</p>
  <pre><code>help
  select
  </code></pre>
  <p>when I would have expected</p>
  <pre><code>help
  help
  </code></pre>
  <p>because I want the respective command names for <code>Help</code> and <code>Select</code> to stay fixed no matter what instances of either command I instantiate. Is the only solution to create a <code>commandName</code> field for every class, or is there a less repetitive way to do this?</p>