473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Call to base method

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() ?

Nov 16 '05 #1
3 1632
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
"Janaka" <ja*****@hotmail.com> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
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() ?

Nov 16 '05 #2
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/<Oe**************@TK2MSFTNGP12.phx.gbl>

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]
Nov 16 '05 #3
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
"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:Or**************@TK2MSFTNGP14.phx.gbl...
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/<Oe**************@TK2MSFTNGP12.phx.gbl>

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]

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; ...
4
by: Amy Matlock | last post by:
Hi all: How does the hardware work if you invoke a BASE::METHOD() on a DERIVED class member? Do you still hit the v-table dynamically at run time? Suppose you have a derived class method, but...
9
by: keith | last post by:
I created a class libery which has name space Assembly and class Assembly and compiled it. Then created a C# project and called a method in the external class e.g. Assembly dll;...
15
by: jon | last post by:
How can I call a base interface method? class ThirdPartyClass :IDisposable { //I can not modify this class void IDisposable.Dispose() { Console.WriteLine( "ThirdPartyClass Dispose" ); } } ...
6
by: active | last post by:
In Protected Overrides Sub OnDrawItem should I call MyBase.OnDrawItem(e) at the top or bottom of the sub? What might happen if I don't call it?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.