I have the following scenario. I subclassing and would like to know what happens to the superclass after the child class is gone
Following is my implementation:
class Program
{
static void Main(string[] args)
{
using (var a = new SuperHuman())
{
}
Console.ReadLine();
}
}
class Human : IDisposable
{
public string LoType = "Normal";
public Human()
{
Console.WriteLine("Human Created");
}
public string GetHumanType()
{
return LoType;
}
public void Dispose()
{
Console.WriteLine("{0} Human Class gONE", LoType);
}
}
class SuperHuman : Human
{
public SuperHuman()
{
LoType = "Super";
Console.WriteLine("{0} Human Created",LoType);
}
}
gives me the following Output:
Human Created
SuperHuman Created
SuperHuman Class Gone
What I would like to know is if the Parent class is gone as well if not how do I dispose it along with the child class?
SuperHuman, you're not actually creating two objects... you're just creating one. So yes, your object has been disposed.LoType). If the base class implemented a constructor with the LoType as parameter (or an abstract property), and the output would show that type, you would also only see the 'creation' of the superhuman class. Dispose only shows an output including the lotype and is not overridden in the inheriting class