You can
NEVER override a variable. It doesn't matter if the variable is defined in an interface and/or a class, you simply can't override a variable. Only methods can be overridden! That's a 1st (very) important rule,
you should remember.
But you can hide (or shadow) a variable. And that's what you see in your example. The
PASSING_SCORE variable in class
Programmer looks exactly the same as the one in the
Certifiable interface, but isn't. It's just another variable which happens to have the same name as the variable defined in the interface. So the variable in the
Programmer class is hiding/shadowing the one in the
Certifiable interface. Easily illustrated when you change the
writePracticeExam method a little bit:
And there was another pointer in your example to prove it wasn't an override: to have a valid override the access modifier can never be more restrictive than the one definied. So all methods & variables in your interface are inheritly
public, but the variable in
Programmer has default access level (which is more restrictive than
public). So because you could compile & run the program, this could not be an override
Hope it helps!