I’m preparing some exercise for the keyword final. It is use to define methods that can’t be overridden in its subclasses.
But I have a problem to find some real good simple real world examples where I want to avoid that a method is overridden in the subclass.
Any hints?
Implementations of
equals()method for not abstract classes must be marked with final modifier. This statement can be easily proved by example (real code from standard library):That means that equals() contract is violated:
but