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
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 constructor overloading in oop?
Why do we use inheritance?
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.
Is enum a class?
What is oops and its features?
What is class and example?
c++ program to swap the objects of two different classes
What is polymorphism what is it for and how is it used?
What is destructor give example?
i=20;k=0;
for(j=1;k-i;k+=j<10?4:3)
{
cout< Who invented oop? Why do pointers exist? What is the purpose of enum? Why is object oriented programming so hard?