Concrete method in abstract class

47,177

Solution 1

can subclasses inherit/override concrete methods from an abstract superclass

If they are not final, yes, they can be overriden.

And secondly do they have to implement concrete methods the same way they implement abstract methods?

No, they only need to implement/override the abstract ones, otherwise an abstract method wouldn't make sense.

Solution 2

A concrete method means, the method has complete definition but it can be overridden in the inherited class. If we make this method "final" then it can not be overriden. Declaring a method or class "final" means its implementation is complete. It is compulsory to override the abstract methods in the subclass otherwise the subclass would also be an abstract class and has to be declared abstract.

Solution 3

Can subclasses inherit/override concrete methods from an abstract superclass ?

Subclasses will inherit all the methods which are marked public or protected, if the subclass is in a different package than the parent class. If the subclass is in the same package, it inherits all the methods except private methods.

The subclass has to override/implement abstract methods and can override/implement concrete methods if they are not marked as final.

Do they have to inherit concrete methods the same way they inherit abstract methods?

No. They don't have to implement the concrete methods. But, they can override the concrete methods, unless they are not marked final.

Solution 4

Concrete methods in Java are nothing but just like any other normal methods. The methods which are not abstract methods are called to be concrete methods in java. If we want to execute those concrete methods create an instance(object) of the class and call to that specific method.

If you declare an abstract method in a class then you must declare the class abstract as well. you can’t have an abstract method in a concrete class. In Java, it is not possible to instantiate an abstract class. An abstract class may contain abstract and concrete methods (i.e with body implementation).

Yes, subclasses inherit/override concrete methods from an abstract superclass if they are not private, final or static, they can be overridden.

No, They don't have to implement the concrete methods. But, they can override the concrete methods, unless they are not marked final.

Share:
47,177
user2240664
Author by

user2240664

Updated on July 05, 2022

Comments

  • user2240664
    user2240664 almost 2 years

    I understand an abstract class may contain abstract and concrete methods (i.e with body implementation). My question are: can subclasses inherit/override concrete methods from an abstract superclass. And secondly do they have to implement concrete methods the same way they implement abstract methods?

  • Stephen C
    Stephen C over 4 years
    This answer seems to imply that a final method is not concrete (because that means that it cannot be overridden). That is certainly not what "concrete" means. See stackoverflow.com/questions/59951096 for the official JLS definition of the term "concrete method".