A
ad
base only can call the parent 's method
The result of the example below is
I am Parent
I am Child
How can we call the grandparent's method in a inhreited class,
I want the result is
I am GrandParent
I am Child
--------------------------------------------------------------------------
using System;
class Test
{
static void Main()
{
Child aChild = new Child() ;
aChild.WhoAmI();
Console.Read() ;
}
}
class GrandParent
{
public virtual void WhoAmI()
{
Console.WriteLine("I am GrandParent");
}
}
class Parent : GrandParent
{
public virtual void WhoAmI()
{
Console.WriteLine("I am Parent");
}
}
class Child : Parent
{
public virtual void WhoAmI()
{
base.WhoAmI();
Console.WriteLine("I am Child");
}
}
The result of the example below is
I am Parent
I am Child
How can we call the grandparent's method in a inhreited class,
I want the result is
I am GrandParent
I am Child
--------------------------------------------------------------------------
using System;
class Test
{
static void Main()
{
Child aChild = new Child() ;
aChild.WhoAmI();
Console.Read() ;
}
}
class GrandParent
{
public virtual void WhoAmI()
{
Console.WriteLine("I am GrandParent");
}
}
class Parent : GrandParent
{
public virtual void WhoAmI()
{
Console.WriteLine("I am Parent");
}
}
class Child : Parent
{
public virtual void WhoAmI()
{
base.WhoAmI();
Console.WriteLine("I am Child");
}
}