Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one abstract class extend another abstract class and increase functionality

I have an abstract class. I want to extend the abstract class by another abstract class and then implement the extended abstract class. Is it possible .If yes, whether it's a good approach in point of view regarding OOPS?

like image 882
Saurabh Kumar Avatar asked Jul 19 '11 07:07

Saurabh Kumar


People also ask

Can a abstract class extend another abstract class?

An abstract class can extend another abstract class. And any concrete subclasses must ensure that all abstract methods are implemented. Abstract classes can themselves have concrete implementations of methods. These methods are inherited just like a method in a non-abstract class.

Can an abstract class implement an abstract class?

We cannot create objects of an abstract class. To implement features of an abstract class, we inherit subclasses from it and create objects of the subclass. A subclass must override all abstract methods of an abstract class. However, if the subclass is declared abstract, it's not mandatory to override abstract methods.

Can abstract class extend another normal class?

I earlier learned that abstract class can extend concrete class. Though I don't see the reason for it from JAVA designers, but it is ok. I also learned that abstract class that extends concrete class can make overriden methods abstract.

What happens when you extend an abstract class?

We can treat an abstract class as a superclass and extend it; its subclasses can override some or all of its inherited abstract methods. If through this overriding a subclass contains no more abstract methods, that class is concrete (and we can construct objects directly from it).


1 Answers

I'm not sure about Java in particular, but it should be valid.

In terms of OOP, if it makes sense, then run with it. To use some old examples, you might have a Vehicle abstract class and then LandVehicle and FlyingVehicle abstract classes. As long as your example makes sense as an abstract class, then you should be fine.

like image 167
Matthew Scharley Avatar answered Sep 19 '22 11:09

Matthew Scharley