C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 13)
Which of the following concepts provides facility of using object of one class inside another class?
Answer: Option
No answer description is available. Let's discuss.
48 comments Page 2 of 5.

Sachin kunte said:   7 years ago
Composition means containment. Where one object may contain attributes of other object.

Lovish said:   8 years ago
In inheritance, we can use data members and member function the class which is inherited but in composition you can initialise the object of other class and with the help of that object you can access its members.

For example:

class a
int x;

class b:public a

// But in composition,

class a
int x;

class b
a obj;

We can't access x directly in other class.

We have to create obj of that class but in inheritance we can do.

ABHI said:   8 years ago
This answer should be abstraction.

Sneha bele said:   9 years ago
Can anyone give clear explanation of difference between Inheritance and Composition with examples of both?

Karthik said:   9 years ago
Inheritance is the answer. Its the class inside another existing class.

Answer C is wrong.

Rahul said:   9 years ago
Containment and composition are same.

Rupali Kate said:   9 years ago
Inheritance and composition are two different concepts:

Inheritance deals with classes and the composition deals with objects.

Composition means deriving a complex object from a simpler object.

Suchita said:   9 years ago
What is the difference between Containment and Composition?

Sarang patarnge said:   9 years ago
Inheritance is relation in which, one class shares behaviors of one or more classes. Also in inheritance, subclass represents general behavior of its super class.

In composition allows physical grouping of logically related structures while inheritance allows common groups to be easily reused among different abstractions.

Eg. Room has wall, System unit has motherboard.

Sarang patrange said:   9 years ago
When object is made from other small object it is called composition?

Post your comments here:

Your comments will be displayed after verification.