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

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

281total visits,6visits today


mayank

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

Related articles

8 Comments

  1. 1
    October 14, 2016 - 4:15 pm

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

  2. October 16, 2016 - 4:44 am

    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. December 1, 2016 - 8:44 pm

    Thank you for sharing your thoughts. I really appreciate your efforts and I will be waiting for your next post thanks once again.

  4. December 2, 2016 - 2:43 am

    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.

  5. December 7, 2016 - 7:02 am

    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.

  6. December 19, 2016 - 11:32 am

    It’s very simple to find out any topic on web as compared
    to books, as I found this post at this web page.

  7. January 23, 2017 - 9:02 am

    My brother recommended I might like this website. He was entirely right. This post truly made my day. You cann’t imagine simply how much time I had spent for this information! Thanks!

Leave a Reply

EmailEmail
PrintPrint