C# Programming - Inheritance - Discussion
Discussion Forum : Inheritance - True or False (Q.No. 13)
13.
It is illegal to make objects of one class as members of another class.
Discussion:
4 comments Page 1 of 1.
Sanjeev kumar verma said:
9 years ago
This is wrong answer.
We can have a member variable of type string.
And as we know string itself is object of string class.
class A
{
public string a; // a object as an member of class A
a= new String() // Object of string class as member of call A
}
Basically aggregation and Has-A relationship depends on it.
We can have a member variable of type string.
And as we know string itself is object of string class.
class A
{
public string a; // a object as an member of class A
a= new String() // Object of string class as member of call A
}
Basically aggregation and Has-A relationship depends on it.
Sumanth reddy said:
8 months ago
No, it is not illegal to make objects of one class as members of another class in C#. This practice is quite common and is an essential part of object-oriented programming.
It is known as composition, where a class contains references to other objects, using them as part of its internal state or behaviour.
It is known as composition, where a class contains references to other objects, using them as part of its internal state or behaviour.
Kapil Hedaoo said:
1 decade ago
Please explain with an example.
Anshul jain said:
9 years ago
Any one explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers