Can we declare final method in abstract class?


If a method in a class is defined as final, then we can’t provide the re-implementation for that final method in it’s derived classes i.e overriding is not possible for that method.

An abstract class contains one or more abstract method.

  • We can have concrete(non-abstract) methods declared as final as it contains both definition and declaration in abstract itself.
  • However, we cannot define abstract methods as final, since the class inheriting our abstract class cannot define/re-implement them.

Example:

abstract class Shape
{
    protected String name;

    abstract void draw();
    abstract void paint();

    final String getNameOfShpae() {
        retrun "Name of the Shape is"+name;
    }
}

 

8 thoughts on “Can we declare final method in abstract class?

  1. K's avatar K November 10, 2010 / 6:22 am

    You cannot have final abstract methods in java as both contradicts to each other

  2. ab exercises to lose belly fat's avatar ab exercises to lose belly fat September 20, 2013 / 7:35 pm

    Every weekend i used to pay a quick visit this web page, for the
    reason that i wish for enjoyment, as this this website conations actually nice funny information
    too.

  3. Arlie's avatar Arlie September 20, 2013 / 9:55 pm

    This is a topic which is near to my heart…
    Cheers! Where are your contqct details though?

  4. Teresa's avatar Teresa September 21, 2013 / 3:14 pm

    Appreciiate this post. Let me try itt out.

  5. linux vps's avatar linux vps January 10, 2014 / 10:58 pm

    I аm not sure where you’re getting your info, but good topic.
    I needs to spend some time learning much mοre or understanding more.
    Thanks for magnificent info I was loοking for this information for my mission.

  6. proactol plus's avatar proactol plus January 21, 2014 / 9:48 am

    Hi there, I read your blogs daily. Your humoristic style is awesome, keep
    doing what you’re doing!

  7. lango montavimas's avatar lango montavimas March 12, 2014 / 7:37 pm

    wonderful post, very informative. I wonder why the other
    experts of this sector don’t understand this. You must proceed your writing.
    I am confident, you have a great readers’ base
    already!

  8. 3g mobile games's avatar 3g mobile games April 15, 2014 / 1:26 pm

    Thanks for finally writing about >Can we declare final method
    in abstract class? | Java Tutorials <Loved it!

Leave a reply to K Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.