InterviewSolution
| 1. |
Can You Explain The Final Method Modifier? |
|
Answer» Java lets you extend ONE CLASS (the SUPERCLASS) with another (the subclass). When a subclass extends a class, the subclass can override the superclass methods. In some CASES depending on a method's , purpose, you may want to prevent a subclass from overriding a specific method. When you declare a class method as FINAL, another class cannot override the methods. Methods which you declare static or private are implicitly final. To declare a method as final, simply precede the method header with the final keyword, as shown: public final CannotOverrideThisMethod(); Java lets you extend one class (the superclass) with another (the subclass). When a subclass extends a class, the subclass can override the superclass methods. In some cases depending on a method's , purpose, you may want to prevent a subclass from overriding a specific method. When you declare a class method as final, another class cannot override the methods. Methods which you declare static or private are implicitly final. To declare a method as final, simply precede the method header with the final keyword, as shown: public final CannotOverrideThisMethod(); |
|