Remove override Solution – 3: final method

Final method is 3rd solution of stop override in java programs. If we use final method in our super class, so we can’t use same name method in any sub class. If we add same name method with same parameter in sub class then java program generate compile time error.

Final Method Example 

class A

{

                final void method()         // final methods can’t override

                {

                                System.out.println(“Welcome in A Class”);

                }

}             

class B extends A

{

                void method()   // Can’t override final methods [compile time error]

                {

                                System.out.println(“Welcome in A Class”);

                }

}

class inh7

{

                public static void main(String args[])

                {

                                B b1 = new B();

                                b1.method();

                }

}

 

Output:

Note: This program generate compile time error.

 

About Programs.

In this program, Super class A has one final method() function, so when create same name method in sub class B, program generate compile time error.

 

Video available on YouTube.


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

1186total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

7 responses to “Remove override Solution – 3: final method”

  1. Hi, the whole thing is going sound here and ofcourse every one is sharing information, that’s really good, keep up writing.

  2. Hey there! I’ve been reading your site for some time now and
    finally got the courage to go ahead and give you a shout out from Kingwood Texas!
    Just wanted to tell you keep up the excellent job!

  3. Greetings I am so glad I found your blog page, I really found you
    by error, while I was browsing on Yahoo for something else,
    Anyways I am here now and would just like to say thank
    you for a remarkable post and a all round interesting
    blog (I also love the theme/design), I don’t have time to
    read it all at the minute but I have saved it and also added in your RSS feeds, so when I have time
    I will be back to read a great deal more, Please do keep up
    the fantastic work.

  4. It’s remarkable to pay a quick visit this site and reading the views of
    all colleagues about this paragraph, while I am also
    keen of getting knowledge.