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?
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With