Can one abstract class extend another abstract class and increase functionality

前端 未结 5 807
灰色年华
灰色年华 2021-02-01 03:15

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 g

相关标签:
5条回答
  • 2021-02-01 03:32

    Yes, you can! One abstract class can be extended by another abstract class

    0 讨论(0)
  • 2021-02-01 03:34

    Yes you can do it. And it is good practice if your child class adds more functionality. It allows to move toward specification. Your parent class becomes a more general class and child class a more specific one. And you can implement both as per your requirement.

    0 讨论(0)
  • 2021-02-01 03:35

    Yes!

    But it makes sense only if the abstract subclass adds more functionality (abstract or not).

    Otherwise, I don't see the point.

    0 讨论(0)
  • 2021-02-01 03:40

    Yes, it is possible, and I don't see a reason not to use it if you need it (disclaimer: but however there are many ways to misuse this, and to over-complicate things, as with everything in programming usually).

    One thing to notice is that the second abstract class doesn't need to implement abstract methods from first class, but the first concrete must implement both.

    0 讨论(0)
  • 2021-02-01 03:51

    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.

    0 讨论(0)
提交回复
热议问题