I need a parent public abstract class which will have multiple child public static classes. I need only one instance of a Weapon class, a few static classes Bow, Sword< etc which extend the parent and can exist also only in one instance (at least I need to be able to get their static fiels). How to do it properly?
public abstract class Weapon {
...
}
public static class Bow extends Weapon {
static String type = "Bow ";
static int damage = 10;
}
public static class Sword extends Weapon {
static String type = "Sword";
static int damage = 10;
}
Getting error:
Illegal modifier for the class Sword; only public, abstract & final are permitted
I removed static and it worked:
public final class Sword extends Weapon {
static String type = "Sword";
static int hitPointsTaken = 10;
}
I can compile this System.out.println( Sword.type );
but not this System.out.println( Weapon.Sword.type );
. Does it mean that I cannot access child through parent abstract?