How do i properly delcare an instance of a subclass in java?
<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. (its rather handy)</p>

<p>I have not been programming with java for a long time, i started learning it a few weeks ago.</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 Item and it has two subclasses: Weapon and Armour. (at the moment)</p>

<p>However, no matter which way i try and declare it in, the IDE im using (Eclipse) flags the line with the following error: </p>

<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>

<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 instance a Weapon (so i can set the values of its fields and give it to the player) i would greatly appciate this.</p>

<p>Also for some reason it does not want to display the code structure for the Item class properly, i am sorry about that.</p>
