1final access modifier can be used for class, method and variables.
2The main advantage of final access modifier is security no one can modify
3our classes, variables and methods.
4The main disadvantage of final access modifier is we cannot implement
5oops concepts in java.
6Ex : Inheritance, polymorphism.
7final class : A final class cannot be extended or subclassed.
8We are preventing inheritance by marking a class as final. But we can still
9access the methods of this class by composition.
10Ex: String class
11final methods: Method overriding is one of the important features in java.
12But there are situations where we may not want to use this feature.
13Then we declared method as final which will print overriding. To allow a method
14from being overridden we use final access modifier for methods.
15final variables : If a variable is declared as final ,it behaves like
16a constant . We cannot modify the value of final variable. Any attempt
17to modify the final variable results in compilation error. The error is like
18“final variable cannot be assigned.”