Recently i saw a question where in it says “How you can stop from subclass overriding your methods in the inheritance hierarchy”.
The solution was simple but did not flashed into my brains. By using sealed keyword in the method signature along with override, you can stop the overriding tree growth.
Let me show you an example:
Now lets see internally what the compiler trick is:
Actually the compiler uses Final keyword internally for sealing the method. Hence the tree growth stops here. Note here that, the Final keyword is not an replacement for Sealed keyword just like Family for Protected access modifier.
If you use the same Sealed keyword for a class, the compiler does not replaces it with Final. So Final keyword is only specific to sealing a method and not a class.