C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 13)
13.
Which of the following concepts provides facility of using object of one class inside another class?
Discussion:
48 comments Page 2 of 5.
Sachin kunte said:
9 years ago
Composition means containment. Where one object may contain attributes of other object.
Lovish said:
9 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
{
public:
int x;
}
class b:public a
{
x=10;
}
// But in composition,
class a
{
public:
int x;
}
class b
{
a obj;
obj.x=10;
}
We can't access x directly in other class.
We have to create obj of that class but in inheritance we can do.
For example:
class a
{
public:
int x;
}
class b:public a
{
x=10;
}
// But in composition,
class a
{
public:
int x;
}
class b
{
a obj;
obj.x=10;
}
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:
9 years ago
This answer should be abstraction.
Sneha bele said:
10 years ago
Can anyone give clear explanation of difference between Inheritance and Composition with examples of both?
Karthik said:
10 years ago
Inheritance is the answer. Its the class inside another existing class.
Answer C is wrong.
Answer C is wrong.
Rahul said:
1 decade ago
Containment and composition are same.
Rupali Kate said:
1 decade 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.
Inheritance deals with classes and the composition deals with objects.
Composition means deriving a complex object from a simpler object.
Suchita said:
1 decade ago
What is the difference between Containment and Composition?
Sarang patarnge said:
1 decade 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.
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:
1 decade ago
When object is made from other small object it is called composition?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers