Hi Guys,
The question belongs to .NET but, I need to analyze number of applications where I can use it. Because .Net People may not know because .NET does not support Multiple inheritance. But this is something different than multiple inheritance. Please suggest the real time applications where I can use this concepts.
The question is - if it possible. Please don't say that this is not possible in .NET.
I am just giving a basic concept, please think it in deep.
Let me proceed right away,
Let's assume the following classes,
public class A
{
public string PropA { get; set; }
public void MethodOfA()
{
Console.WriteLine("Calling MethodOfA from A");
}
public void MethodOfB()
{
Console.WriteLine("Calling MethodOfB from A");
}
}
public class B
{
public string PropA { get; set; }
public string PropB { get; set; }
public void MethodOfA()
{
Console.WriteLine("Calling MethodOfA from B");
}
}
public class C : A, B
{
}
Class C is derived from A and B classes
Now, class A and B both contains a common method MethodOfA()
So, when I say
Collapse
C c = new C();
c.MethodOfA();
It calls MethodOfA() from A and then it calls MethodOfA from B sequentially.
And the output will be
Calling MethodOfA from A
Calling MethodOfA from B
Now, when I say
Collapse
C c = new C();
c.A.MethodOfA();
It calls method of A only and same for B class.
And the output will be
Calling MethodOfA from A
So, I can call method in a row at one shot or I can call it by class name.
Same thing we can apply for the properties too.
We can set properties at one shot or we can get property at one shot.
We can set property by a class name or we can get property by a class name.