0

I am fairly new at programming (especially in java) and had a question regarding inheritance in java. I understand the syntax for inheritance (class newPlayer extends Player) but am wondering if all the source code or something has to be in the same folder or imported or something for java to detect it.

Im working on a school assignment and had to download the .java class file and inherit from it. I am also using eclipse to work on this project. Right now I'm just getting the message that I need to create a Player class. hope this all makes sense!! ANy help would be much appreciated.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Danger Cat
  • 39
  • 2
  • 5
  • What is the **exact** message you are getting? Can you post a [SSCCE](http://sscce.org/)? – Thorn G Oct 25 '13 at 17:51
  • 1
    based on `class newPlayer extends Player` it kind of seems like you want to create an instance of `Player`, but maybe not. If you do you just have to say `Player newPlayer = new Player();` But that wont get rid of your error. – clcto Oct 25 '13 at 17:53
  • [Your question has been answered here.][1] [1]: http://stackoverflow.com/questions/7869006/import-a-custom-class-in-java – cube Oct 25 '13 at 17:59

3 Answers3

1

No, it has to only be on project's class path for the compiler and eclipse to see it.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
1

'Ctrl+Shift o' if its in your path this will add the import.

If your new be careful of extend v implements.

Tony
  • 345
  • 1
  • 4
  • 11
0

It can be done both ways. If class Player is not in the same package as newPlayer, then you need an import statement. If they are in the same package you don't need one.

fvrghl
  • 3,642
  • 5
  • 28
  • 36