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;
};
kind of relationship
has a relationship
Inheritance
Both A and B
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
8 comments Page 1 of 1.

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.

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.

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

Anonymous1 said:   1 decade ago
But, how can we create an obj of a class before even creating it?

Pragna said:   10 years ago
A bike "has a" engine. So this becomes "has a" relationship.

Paras Santoki said:   1 decade ago
How it represent has a relationship?

Can any one explain?

Vrushali said:   10 years ago
Can anyone explain how it is 'has a relationship'?

Post your comments here:

Your comments will be displayed after verification.