Can We Extend final Method in Java? Last Updated : 19 Jul, 2022 Comments Improve Suggest changes Like Article Like Report Final method in java can be extended but alongside the main concept to be taken into consideration is that extend means that you can extend that particular class or not which is having final method, but you can not override that final method. One more case where you can not extend that final method is the class that contains the final method is also a final class. Approaches: Here we will be discussing out two approaches in order to satisfy what we just stated above to figure out how the final method is extended. Without over-ridingWith over-riding Implementation: 'GFGParent' class is having a final method randomly named it 'dataDisplay()' which is created as the final method here.'GFG' class extends GFGParent but the program executes without any error hence we can extend a final method but can not override it.Here if you had made the GFGParent class as final as also you will not extend the final method as we can not inherit the final classes. Example 1 Java // Java Program to Illustrate Final Method Extension // Importing input output classes import java.io.*; // Class 1 // Child class // Main class class GFG extends GFGParent { // Main driver method public static void main (String[] args) { // Print statement System.out.println("GFG!"); // Creating an object of parent class in child class // inside the main() method GFGParent gfg = new GFGParent(); // Calling the method created in parent class gfg.dataDisplay(); } } // Helper class // Parent class class GFGParent { public final void dataDisplay () { System.out.println("Data Structure"); } } OutputGFG! Data Structure Example 2 The only change that we will be making here is we are simply trying to override the method inside child class. Java // Java Program to Illustrate Final Method Extension // Where method Overrides // Importing input output classes import java.io.*; // Class 1- Parent class class GFGParent { // Method inside parent class public final void dataDisplay() { System.out.println("Data Structure"); } } // Class 2 // Child class // Main class class GFG extends GFGParent { // Method 1 // Created in order to illustrate overridden method/s public final void dataDisplay() { // Print statement whenever this message is called System.out.println("Data Structure 2"); } // Method 2 // Main driver method public static void main(String[] args) { // Print statement System.out.println("GFG!"); // Creating an object of parent class and // calling method of child class over it. GFGParent gfg = new GFGParent(); gfg.dataDisplay(); } } Output: It generates a compile-time error. Comment More infoAdvertise with us Next Article Can We Extend final Method in Java? R rajatagrawal5 Follow Improve Article Tags : Java Java-final keyword Practice Tags : Java Similar Reads Private and Final Methods in Java Methods in Java play an important role in making the code more readable, support code reusability, and defining the behaviour of the objects. And we can also restrict the methods based on requirements using the keywords and modifiers such as final and private. These two have different, distinct purp 5 min read Can We Override Final Method in Java? A method in a subclass is said to Override a method in its superclass if that method has a signature identical to a method in its superclass. When this method is called by an object of the subclass, then always the Overridden version will be called. In other words, the method which was Overridden in 3 min read Can We Override Default Method in Java? Default method in Java is a method in java which are defined inside the interface with the keyword default is known as the default method. It is a type of non-abstract method. This method is capable of adding backward capability so that the old interface can grasp the lambda expression capability. J 3 min read Java Extension Methods In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. Extension methods are features of some object-oriented programming languages. There is no syntactic difference between calling an extension method and calling a method 4 min read Calendar complete() Method in Java with Examples The complete() method in Calendar class is used to fill any unset fields of the calendar fields. It follows the following process of completion: At first, if the time value has not been calculated, the computeTime() method is called to calculate it from calendar field values. Second, to calculate al 2 min read Like