C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - General Questions (Q.No. 17)
17.
What does the class definitions in following code represent?
class Bike
{
Engine objEng;
};
class Engine
{
float CC;
};
Discussion:
8 comments Page 1 of 1.
Pragna said:
10 years ago
A bike "has a" engine. So this becomes "has a" relationship.
Vrushali said:
10 years ago
Can anyone explain how it is 'has a relationship'?
Anonymous1 said:
1 decade ago
But, how can we create an obj of a class before even creating it?
Akahay s said:
1 decade ago
But inheritance rule is only derived class can access base, base class can not access derived class.
Ankit.w. said:
1 decade ago
This method is also called as 'containership' or 'nesting of classes'.
Mannu said:
1 decade ago
Here class bike inside have created the object of engine class. So we can easy to access data member of engine class.
Vasanth said:
1 decade ago
Here by creating the Engine objEng in the Class Bike will make a access to the Class Engine and also the data member of the Class Engine, Only if it (Class Bike) is having the Member function. And By this we can access the data member of the Class Bike via Class Engine itself.
I think this reason is correct, if anything is wrong please correct me with exact reason.
I think this reason is correct, if anything is wrong please correct me with exact reason.
Paras Santoki said:
1 decade ago
How it represent has a relationship?
Can any one explain?
Can any one explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers