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.
This program demonstrates the concept of final methods in Java.
//Final Methods in Java class Super { public void display() { System.out.println("I am Super Display"); } final void finalDisplay() { System.out.println("I am Super Final Display"); } } class sub extends Super { public void display() { System.out.println("I am Sub Display"); } } public class finalMethods { public static void main(String args[]) { sub o =new sub(); o.display(); o.finalDisplay(); } }
I am Sub Display I am Super Final DisplayTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions