0

I have two classes, in class Player i have the variable which is defined as private int collectedDots and I want to access in another class Exit.

I have defined the Get and Set method within class Player as such:

public void setCollectedDots(int cd)
{
    collectedDots = cd;
}

public int getCollectedDots()
{
    return collectedDots;
}

But now I want to access the collectedDots field from the Exit class. When I copy those two methods into the Exit class I keep getting the error cannot find symbol - variable collectedDots.

It was my understanding that I would then be able to retrieve the collectedDots variable from the Player class once I set the get and set methods..

Any ideas where i'm going wrong?

Rookie007
  • 1,229
  • 2
  • 18
  • 50
user3509273
  • 31
  • 2
  • 5
  • 6
    You need to call the methods on the Player in Exit, not copy them there. – PurkkaKoodari Apr 21 '14 at 01:53
  • @Pietu1998: you should probably make that an answer – Lie Ryan Apr 21 '14 at 02:22
  • @Pietu1998 I have tried doing that, I have an if statement that reads if (Player.getCollectedDots < 3) but it says I need to define the variable .setCollectedDots first, but I don't want to define it in the Exit class, I just want to call it. – user3509273 Apr 21 '14 at 11:33

2 Answers2

1

I'm not yet that familiar with java but i guess you need to make sure that you have imported the other class that you would use or you can you an instance of a class:

collectedDots dots = new collectedDots(); int dotsValue = dots.getCollectedDots();

mj930112
  • 80
  • 1
  • 10
-2

You should use public int collectedDots variable rather than private int collectedDots variable

pushkin
  • 9,575
  • 15
  • 51
  • 95