title: How do I properly declare an instance of a subclass?
body: <p>I am currently making a text based adventure in Java for the purposes of using it a test platform, to try out new things I learn from this Java book I'm reading.</p>
  
  <p>I am now trying to declare an instance of a subclass (as the player is scripted to find it).
  The parent class is <code>Item</code> and it has two subclasses: <code>Weapon</code> and <code>Armour</code>.</p>
  
  <p>However, no matter which way I try and declare it in, the IDE I'm using (Eclipse) flags the line with the following error: </p>
  
  <blockquote>
    <p>No enclosing instance of type Item is accessible. Must qualify the allocation with an enclosing instance of type Item (e.g. x.new A() where x is an instance of Item).</p>
  </blockquote>
  
  <p>When I attempt to declare it like any of the following:</p>
  
  <pre><code>Item machinePistol = new Weapon(); 
  Weapon machinePistol = new Weapon();
  Item machinePistol = new Item.Weapon();
  Weapon machinePistol = new Item.Weapon();
  </code></pre>
  
  <p>For reference the item class looks like this:</p>
  
  <pre><code>package JavaAIO;
  
  public class Item 
  {
      public String itemName;
      public double itemWeight;
  
      public class Weapon extends Item
      {
          public double damage;
          public double speed;
      }
      public class Armour extends Item
      {
          public double dmgResist;
          public double attSpdMod;    
      }
  }
  </code></pre>
  
  <p>So if anyone could tell me how I could properly instantiate a Weapon (so I can set the values of its fields and give it to the player), I would greatly appreciate it.</p>