- 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
What is 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
public class FinalMethodExample { public final void display(){ System.out.println("Hello welcome to Tutorialspoint"); } public static void main(String args[]){ new FinalMethodExample().display(); } class Sample extends FinalMethodExample{ public void display(){ System.out.println("hi"); } } }
Output
FinalMethodExample.java:12: error: display() in FinalMethodExample.Sample cannot override display() in FinalMethodExample public void display(){ ^ overridden method is final 1 error
- Related Articles
- Is final method inherited in Java?
- What is a final variable in java?
- What is a final parameter in java?
- What happens when you declare a method/constructor final in Java?
- Can we inherit a final method in Java?
- What is final parameter in Java
- What is a blank uninitialized final variable in java?
- What is blank final variable? What are Static blank final variables in Java?
- What is static blank final variable in Java?
- Is StringBuffer final in Java?
- What is blank or uninitialized final variable in Java?
- What are final classes in Java?
- Explain final class and final method in PHP.
- Can we declare the main () method as final in Java?
- Can a method local inner class access the local final variables in Java?

Advertisements