Welcome to the Ranch
You should make the fields in both your classes private, and access them
via methods. But, in the current code, you declare the variable as type Person. Now some Person objects have a score field and some don't. If you declare it as Person, you can do this:-
... or this:--
Now, when you get to line 5, you have an object which does not have a score field. What are you going to do? Are you going to allow that assignment because some Person objects do have a score field? And what will happen at runtime, an Exception or something?
You are
notnow in the realms of “behaviour undefined”, and that is dangerous. How can you be sure your program will behave correctly? How can you even say what correct behaviour is?
The correct answer is that the program cannot run. And the best way to ensure that a program does not run is not to allow it to compile in the first place. A Player is a Person, so you would expect the assignment to a Player (line 3) to run correctly.
So, you would expect the compiler error when you try to access the score field.
[edit]Correct not to now.