Call to base method

  • Thread starter Thread starter Janaka
  • Start date Start date
J

Janaka

When using object inheritance is it possible to call a method of the base
class more than 1 object below the inherited class?
For example, assume that the Labrador class inherits all the way down to
animal - Labrador -> Dog -> Animal
Animal has a virtual method called Walk() which is overridden in Dog
Now if I use the following code this will call Dog's implementation.:
public override void Walk()
{
base.Walk();
}

Is it possible to call Animal's implementation of Walk() ?
 
Given my understanding of Object inheritance, you will need to call
base.walk in Dog to get the animal.walk to be called. I don't believe just
under general OOP principles you should ever be able to have access to
animal directly from Lab given you inherited from Dog.

--
Thanks
Wayne Sepega
Jacksonville, Fl

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 
No, this isn't supported in C# (unlike C++)

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

When using object inheritance is it possible to call a method of the base
class more than 1 object below the inherited class?
For example, assume that the Labrador class inherits all the way down to
animal - Labrador -> Dog -> Animal
Animal has a virtual method called Walk() which is overridden in Dog
Now if I use the following code this will call Dog's implementation.:
public override void Walk()
{
base.Walk();
}

Is it possible to call Animal's implementation of Walk() ?




---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
Ok that sounds about right seeing as C# only supports single-class
inheritance as apposed to the multi-class inheritance in C++.

So looks like its down to organising the classes implementation properly.
Thanks
 
Back
Top