Avatar of gudii9
gudii9
Flag for United States of America asked on

abstract class with all non abstract mentods

Hi,
Can a abstract class with all non abstract mentods? Is that is possible. I am under impression that atleast one method of abstract class should be abstract. What are advantages and practical uses of abstract methods compared to interface. I see many cases abstract class is implements a interface. Then a concrete class extends the abstract class. I wonder what is use of this pattern

interface--->abstract class(implements)--->concrete class(extends)
JavaJava EEProgramming Languages-OtherProgrammingSystem Programming

Avatar of undefined
Last Comment
Jeffrey Dake

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
dpearson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Jeffrey Dake

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gudii9

ASKER
Doug is correct except that in the newest version of Java they have introduced the ability to but a default implementation of a method in an interface. This gives a little more flexibility in trying to do multi inheritance in a class.

any good links or examples on this?
dpearson

Yeah I didn't mention default implementations as I'm concerned it may confuse your understanding if you're not clear on abstract classes vs interfaces yet.

But anywhere here's some info on them:
https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html

(Oracle added this capability so they could extend some existing interfaces in the Java language without breaking a ton of existing code).

Doug
gudii9

ASKER
>> Can a abstract class with all non abstract methods?

Yes there's nothing wrong with that.  It's not common but it's allowed.

it is kind of defeating the purpose for which we create abstract class right?
if we do not have abstract methods in it it seems very uncommon to me.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Jeffrey Dake

Not always, you may just have a whole bunches of functions you want inherited but don't want that base class to ever be instantioated.