10.final Keyword
10.final Keyword
final keyword
• The final keyword has two important uses in the context of a class
hierarchy. These uses are highlighted as follows:
• Using final to Prevent Overriding
– While method overriding is one of the most powerful feature of object
oriented design, there may be times when you will want to prevent
certain critical methods in a superclass from being overridden by its
subclasses.
– Rather, you would want the subclasses to use the methods as they
are defined in the superclass.
– This can be achieved by declaring such critical methods as final.