I\'ve recently picked up Java and have run into a problem. I have several files with different classes, but I can\'t figure out how I can access objects of the other classes
A good place to start would be to pass in the player you want to attack "when" the monster attacks.
battle.java
public class Battle {
public static void main(String[] args) {
Player player = new Player();
Monster monster = new Monster();
monster.attackPlayer(player);
}
}
player.java:
public class Player
{
public int getLocation()
{
return 2;
}
}
monster.java:
public class Monster
{
public void attackPlayer(Player player)
{
player.getLocation();
}
}