How to call the grandparent's method
From: ad (ad_at_wfes.tcc.edu.tw)
Date: 01/24/05
- Next message: Marcin Grzębski: "Re: StreamReader / StreamWriter Encoding"
- Previous message: Abubakar: "Re: strings(seperation)"
- Next in thread: Ranjan: "Re: How to call the grandparent's method"
- Reply: Ranjan: "Re: How to call the grandparent's method"
- Reply: Ignacio Machin \( .NET/ C# MVP \): "Re: How to call the grandparent's method"
- Reply: Rachel Suddeth: "Re: How to call the grandparent's method"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 Jan 2005 19:29:32 +0800
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");
}
}
- Next message: Marcin Grzębski: "Re: StreamReader / StreamWriter Encoding"
- Previous message: Abubakar: "Re: strings(seperation)"
- Next in thread: Ranjan: "Re: How to call the grandparent's method"
- Reply: Ranjan: "Re: How to call the grandparent's method"
- Reply: Ignacio Machin \( .NET/ C# MVP \): "Re: How to call the grandparent's method"
- Reply: Rachel Suddeth: "Re: How to call the grandparent's method"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|