Wednesday, January 9, 2019

Is inheritance necessary for encapsulation, abstraction and polymorphism?

  • Is Encapsulation possible without inheritance?
Yes, because Encapsulation is the ability to hide a class properties from the outside world by means of access methods.
  • Is Abstraction possible without inheritance?
Well, abstraction can refer to many things, but talking about OOP: No, an abstract class cannot be used directly, you can only instantiate inherited classes.
  • Is Polymorphism possible without inheritance?
Yes, polymorphism is the construction of a single interface to several types of objects, for instance, a single function call that can receive different classes or data types as arguments. They can be inherited or not.

No comments:

Post a Comment