class Common
{
public String name;
class Weapon
{
public static boolean Sword;
}
}
PC.Weapons.Sword = true;
PC (player) was a class, and Weapons was an embedded class. Sword is just a static boolean whether the player had a sword or not. I noticed that doing the same in Java is different - inner classes cannot have static variables. How can I achieve a similar result?
Need help with embedded classes in Java
In C++, I was able to do the following (which is now Java syntax)...
I sought, but didn't find, other than everything having to be static.
PC can't access class Weapon. Common can, but that isn't desired, though.
import java.lang.*;class Main{ public static void main(String args[]) { Common PC = new Common(); }} class Common{ public static class Weapon { public static boolean Sword; }}
PC can't access class Weapon. Common can, but that isn't desired, though.
AP, before you posted, I tried exactly what you did. I'm still not able to access Weapon. Error message is "unexpected type" at PC.Weapon.Sword = true; I assume that instantiated objects can't use static variables/methods/classes.
Wouldn't something simple like this suffice?
class Common
{
public String name;
class CommonWeapon
{
public boolean Sword;
}
public CommonWeapon Weapon = new Weapon();
}
class Common
{
public String name;
class CommonWeapon
{
public boolean Sword;
}
public CommonWeapon Weapon = new Weapon();
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement