Re: How to call the grandparent's method
From: Rachel Suddeth (rachel_at_bldhound.com)
Date: 01/24/05
- Next message: Jaroslav Jakes: "Re: StreamReader / StreamWriter Encoding"
- Previous message: TM: "Anyone ever get mailbox rights from CDOEXM using C#?"
- In reply to: ad: "How to call the grandparent's method"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 Jan 2005 09:08:21 -0600
First of all, you want the parent and the child definitions to start like
this....
> public override void WhoAmI()
Then, the first line in each should be
> base.WhoAmI();
You remembered to put that in the child, but it needed to be in the parent,
too, if you wanted the grandparent base method to be called.
-Rachel
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:udEx$fgAFHA.1084@tk2msftngp13.phx.gbl...
> 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: Jaroslav Jakes: "Re: StreamReader / StreamWriter Encoding"
- Previous message: TM: "Anyone ever get mailbox rights from CDOEXM using C#?"
- In reply to: ad: "How to call the grandparent's method"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|