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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Private Methods in Java 9 Interfaces
- Can we override private methods in Java?
- Unreachable statement using final and non-final variable in Java
- Static methods vs Instance methods in Java
- Replacing 'public' with 'private' in "main" in Java
- Private Constructors and Singleton Classes in Java
- How to call private method from another class in Java with help of Reflection API?
- Using final with Inheritance in Java
- Final arrays in Java
- final vs Immutability in Java
- final keyword in java
- Blank Final in Java
- final variables in Java
- final, finally and finalize in Java
- Final static variable in Java
- Final local variables in Java
- Difference between Final and Abstract in Java
- Instance variable as final in Java
- Assigning values to static final variables in Java
- Java.util.BitSet class methods in Java with Examples | Set 2