Write a program in java to demonstrate final method?

class Person

{

                public void print()

                {

                                System.out.println("Hello");

                }

                public final void display()

                {

                                System.out.println("India");

                }

}

class Change extends Person

{

                public void print()

                {

                                System.out.println("Hii");

                }

                public static void main(String arg[])

                {

                                Change x=new Change();

                                x.print();

                                x.display();

                }

}

Without Final Method.PNG

class Person

{

                public void print()

                {

                                System.out.println("Hello");

                }

                public final void display()

                {

                                System.out.println("India");

                }

}

class Change extends Person

{

                public void print()

                {

                                System.out.println("Hii");

                }

                public void display()

                {

                                System.out.println("Hindustan");

                }

                public static void main(String arg[])

                {

                                Change x=new Change();

                                x.print();

                                x.display();

                }

}

Final Method.PNG

, , , , , , ,

Leave a Reply