3

I want to access a return Value from another .Class. Do i rly have to make it static?

For example:

Class 1 Called Player

public int getRemainingItemUses(){
    return remainingItemUses;
}

Class 2

Player.getRemainingItemUses()

My Error is Cannot make a static reference to the non-static method getRemainingItemUses() from the type Player

Skyrisu
  • 373
  • 1
  • 5
  • 14

1 Answers1

3

You can either make getRemainingItemUses() static, or create an instance of Class1 and invoke the method on it:

Class1 c = new Class1();
int result = c.getRemainingItemUses();
Eran
  • 387,369
  • 54
  • 702
  • 768