Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
As we can access the members of a class by creating an instance of it why do we need to use inheritance to use and access its members.Class 1 and Class 2 are the two classes. I want to access all the members of Class 1 inside class 2. I can instantiate a object of class 1 inside Class 2 as well as inheriting the class 1 in the sub class to access the members. I would to like to know why one is preferred and in what kind of situation.

What I have tried:

I have worked on both creating a instance of the class and inheriting in a sub class to access the members of the class.But i don't know why use inheritance is preferred.
Posted
Updated 18-Aug-19 21:54pm

1 solution

This is a 'vexata quaestio', see, for instance: Inheritance VS Composition[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900