- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is final method inherited in Java?
No, we cannot override a final method in Java.
The final modifier for finalizing the implementations of classes, methods, and variables.
We can declare a method as final, once you declare a method final it cannot be overridden. So, you cannot modify a final method from a sub class.
The main intention of making a method final would be that the content of the method should not be changed by any outsider.
Example
class Demo{ public final void demoMethod(){ System.out.println("Hello"); } } public class Sample extends Demo{ public final void demoMethod(){ System.out.println("demo method"); } public static void main(String args[]){ Sample obj = new Sample(); obj.demoMethod(); } }
Output
C:\Sample>javac Sample.java Sample.java:8: error: demoMethod() in Sample cannot override demoMethod() in Demo public final void demoMethod(){ ^ overridden method is final 1 error
- Related Articles
- What is a final method in Java?
- Is constructor inherited in Java?
- Can we inherit a final method in Java?
- Is StringBuffer final in Java?
- Explain final class and final method in PHP.
- Can we declare the main () method as final in Java?
- Are static methods inherited in Java?
- Can constructors be inherited in Java?
- What is final parameter in Java
- Can we declare the method of an Interface final in java?
- What happens when you declare a method/constructor final in Java?
- Can we declare an abstract method final or static in java?
- What is a final variable in java?
- What is a final parameter in java?
- What is blank final variable? What are Static blank final variables in Java?

Advertisements