When we use final specifier with a method, the method cannot be overridden in any of the inheriting classes. Methods are made final due to design reasons.
Since private methods are inaccessible, they are implicitly final in Java. So adding final specifier to a private method doesn’t add any value. It may in-fact cause unnecessary confusion.
For example, both ‘program 1’ and ‘program 2’ below produce same compiler error “foo() has private access in Base”.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Java is Strictly Pass by Value!
- GFact 48 | Overloading main() in Java
- Bitwise right shift operators in Java
- Overriding toString() in Java
- Valid variants of main() in Java
- HashSet vs TreeSet in Java
- ShortBuffer allocate() method in Java With Examples
- IntBuffer duplicate() method in Java with Examples
- ShortBuffer compact() method in Java With Examples
- LongBuffer equals() method in Java