I have the following program and my need is call the parent class method using parent class reference which points to child class object.
class aa
{
public virtual void test()
{
Console.WriteLine("test in parent class");
}
}
class chi:aa
{
public override void test()
{
Console.WriteLine("test in child class");
}
}
class Program:chi
{
static void Main(string[] args)
{
aa ref1 =new chi();
ref1.test();
}
}
}
I need to class the test method of class "aa" using the reference ref1. how to do this?Please help
Ranjit PowarPosted Feb 1, 2016, 6:29 AM
In overriding there is no way to call base class method using instance of child class. If you really want this create another method in child class and call base class method in that method. as below