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 1 of 5.
Hamdan Ali said:
4 years ago
It's a part of Association, where two classes communicate each other but don't have a relationship and inside Association the form of Aggregation where two classes objects can communicate each other but one class denotes as owner and one class denotes its part for example Department has lecturers if department object destroys lecturers will exist another example Address can relate to one and more entity if people those are living on that address leave the address so the address will exist and inside aggregation, the form is composition, whether one entity lifecycle depends on another entity, means like if House and Room relationship if the house will destroy room will also destroy this called composition.
(8)
Sparsh Gupta said:
4 years ago
Inheritance will acquire one class properties, but here the question is not about the class, it's about an object inside a class, so the answer is composition.
(5)
Bhuneshwar Mahto said:
5 years ago
I don't know about composition please tell me, anyone, in detail about composition.
(4)
Sunil said:
6 years ago
Composition is a HAS-A relationship. One class can hold the object of another class and also manages its life-cycle. So we can class A has a B class object.
Inheritance is IS-A relationship. Derived class is derived from the base class. So we can say that derived class is a base class (since it holds all the properties which is in base class).
Inheritance is IS-A relationship. Derived class is derived from the base class. So we can say that derived class is a base class (since it holds all the properties which is in base class).
(2)
Kavi said:
7 years ago
We establish composition (HAS-A) relation between classes if one object cannot exist without another object.
For ex-Student/Employee/anyone cant exist without Address.
Say Student HAS-A address
& Employee HAS-A address
class Address{}
class Student{
Address a=new Address();
}
Similarly
class Employee{
Address a=new Address();
}
For ex-Student/Employee/anyone cant exist without Address.
Say Student HAS-A address
& Employee HAS-A address
class Address{}
class Student{
Address a=new Address();
}
Similarly
class Employee{
Address a=new Address();
}
(1)
Akshay said:
8 years ago
The car has an engine is a composition here we are talking about some part of the car.
The car is a 4wheeler is an inheritance.
The car is a 4wheeler is an inheritance.
(1)
Hardeep said:
1 decade ago
Can anyone explain me relationship between inheritance and composition?
Shivani said:
1 decade ago
Is composition similar to inheritance?
Ashwini said:
10 years ago
Why you answering as composition instead of inheritance?
Payal said:
10 years ago
What is Composition?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers