Write a program to demonstrate the use of 'Composition' in C++
Answer Posted / mahendra
Find the program below to demonstrate the composition.
first define the class called the DataBirth.
class DateOfBirth
{
public:
void UpdateDMY();
void GetDMY();
private:
int date,month,year;
};
define the Employee class.
class Employee
{
public:
void GetDetails();
void UpdateDetails();
private:
DateOfBirth BirthDate;
}
Here the EMployee class is having the object of the
DateOfBirth class as data member. With this the Employee
class is achieving the "has-a" relation with the
DateOfBorth class. In this way the Employee class can have
objects of the many calsses as members.
Is This Answer Correct ? | 14 Yes | 8 No |
Post New Answer View All Answers
What are the benefits of polymorphism?
What is the diamond problem in inheritance?
What is methods in oop?
What is the difference between abstraction and polymorphism?
What does sksksk mean in text slang?
Are polymorphisms mutations?
What does <> mean pseudocode?
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
Why is abstraction used?
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
What is destructor in oop?
What is data binding in oops?
what is different between oops and c++
What is an example of genetic polymorphism?