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
Which language is pure oop?
How do you use inheritance in unity?
hi all..i want to know oops concepts clearly can any1 explain??
What is protected in oop?
What is encapsulation oop?
What is overloading in oops?
What is overriding in oops?
Can abstract class have normal methods?
What is oops with example?
Can bst contain duplicates?
How oops is better than procedural?
Can we override main method?
Explain virtual inheritance?
Get me a number puzzle game-program
What is abstraction in oops?