What is exact difference between Inheritance and Abstract class?

后端 未结 5 904
心在旅途
心在旅途 2021-02-06 00:46

I know the fundamentals of OOP concepts[Inheritance, Abstraction, Encapsulation, Polymorphism]

We use Inheritance in case of Parent-Child relationship[C

5条回答
  •  梦毁少年i
    2021-02-06 01:21

    These are two different concept and selections are based on the requirements.

    Abstraction hide the implementation details and only show the functionality. It reduce the code complexity. Inheritance create a class using a properties of another class. It improve the code reusability.

    So these are two different things for different purposes.

    If this is about the implementation(coding), obviously there are differences than putting abstract keyword in the method name.

    • Can't implement method body in abstract methods in abstract class. But can implement method body in methods in parent class.
    • In inheritance, child class inherits is parents methods. Same as in abstraction also child class inherits non-abstracts methods of parent class as they are. But child class must implement all the abstract methods in parent class, otherwise child class need to be declared as abstract.
    • Can't create instance of abstract class.

提交回复
热议问题