I come from C++, and actually I haven't really used class inheritance at college yet, so I'm learning by myself. I'll put my doubt in the form of an example:
Let's say I have a class called Entity. This entity class holds two integers representing some X and Y coordinates (this is not relevant, it could be any other field). Then I have my class Player, extending Entity. As it might seem usual, I want Player to use as well the x and y fields, and some code in the Entity class refers to those fields as well.
Now comes my doubt. Are x and y public, private or protected? I feel like they should be protected, as public is not an option (Other classes should'nt be accessing it) and private doesn't allow me to use the x and y fields from the extended (Player) class. But I read elsewhere that class fields should never be protected, only methods.
Other sollutions to this other than setting the variable to protected that come into mind would be using getters and setters from the super class (which in my opinion is not only a bad practice but completely redundant and unnecesary), or re-declaring those attributes in the new class, which let's me thinking if I'm getting any reward from inheritance if I'll have to type all the field declarations twice. I actually don't even know if this last thing might work as I don't know Java that well to know how it handles this visibility issues.
Any help on the topic would be much appreciated.
Thank you.