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 1 of 5.

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.

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.

Bhuneshwar Mahto said:   4 years ago
I don't know about composition please tell me, anyone, in detail about composition.

Piyudh said:   5 years ago
I agree, thanks @Sunil.

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).

Khushbu said:   7 years ago
I think right will be inheritance as it inherits attributes and behavior of a class to another class.

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();

class Employee{
Address a=new Address();

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.

Gelu Menumorut said:   8 years ago
The question is very inaccurate, it should have been:.

"Of the defining object of one class as a member of another class?".

Compare this with "Of using object of one class inside another class?".

Actually "using" means to have access to an instance by any mean (even as a parameter) and call it's member functions. None of the options match this trivial functionality, but "None" was provided as an option.

AMOL said:   8 years ago
Inheritance can be know by IS A relationship.

Composition is known by HAS A relationship (its basically a code reuse).

Post your comments here:

Your comments will be displayed after verification.