473,405 Members | 2,445 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,405 software developers and data experts.

inheritance issue

I'm trying to do the following:
Class1 (= base class)
public virtual Method1{}

Class2 : Class1
public override Method1
{
return base.Method1;
//do some more processing specific to Class2
}

Class3 : Class2
public override Method1
{
return base.Method1;
//do some more processing specific to Class3
}

Problem is I'm getting a compile error on Class3.Method1, stating that no
suitable method can be found in Class2 to override.
Question is, how can I override Class1.Method1 in Class2 yet make
Class2.Method1 virtual so Class3 can override it?
I've tried several access modifiers, but I'm getting errors each time.

Any ideas?

-- Hans De Schrijver
Nov 16 '05 #1
2 1197
Hans,

im really not sure if i get your problem right, but
this sample works for me:

using System;

public class MyClass
{
public static void Main()
{
Class3 c3 = new Class3();
Console.WriteLine(c3.Method1());
Console.ReadLine();
}
}
public class Class1
{
public virtual object Method1()
{
return "class1";
}
}
public class Class2 : Class1
{
public override object Method1()
{
return base.Method1();
}
}
public class Class3 : Class2
{
public override object Method1()
{
return base.Method1();
}
}

HTH,

--
gani
http://thedeveloperscorner.com.ph

-----Original Message-----
I'm trying to do the following:
Class1 (= base class)
public virtual Method1{}

Class2 : Class1
public override Method1
{
return base.Method1;
//do some more processing specific to Class2
}

Class3 : Class2
public override Method1
{
return base.Method1;
//do some more processing specific to Class3
}

Problem is I'm getting a compile error on Class3.Method1, stating that nosuitable method can be found in Class2 to override.
Question is, how can I override Class1.Method1 in Class2 yet makeClass2.Method1 virtual so Class3 can override it?
I've tried several access modifiers, but I'm getting errors each time.
Any ideas?

-- Hans De Schrijver
.

Nov 16 '05 #2
Hans De Schrijver <ha**@punctualgraphics.com> wrote:
I'm trying to do the following:
Class1 (= base class)
public virtual Method1{}

Class2 : Class1
public override Method1
{
return base.Method1;
//do some more processing specific to Class2
}

Class3 : Class2
public override Method1
{
return base.Method1;
//do some more processing specific to Class3
}
Please post *actual code*. Your derived classes appear to be trying to
override properties rather than methods, and you haven't specified any
return types.
Problem is I'm getting a compile error on Class3.Method1, stating that no
suitable method can be found in Class2 to override.
Question is, how can I override Class1.Method1 in Class2 yet make
Class2.Method1 virtual so Class3 can override it?
I've tried several access modifiers, but I'm getting errors each time.

Any ideas?


When you post the real code, I'm sure the problem will become apparent.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

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

Similar topics

11
by: Ricky Romaya | last post by:
Hi, Are there any ways to get multiple inheritace in PHP4? For example, I have 3 parent class, class A, B, and C. I want class X to inherit all those 3 classes. Consider merging those 3 classes...
4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
15
by: Sinex | last post by:
Hi, Why does C# disallow multiple inheritance? Whats the reason behind this? Is there any advantage or is it just a method to avoid some problems (if so, what problems?) that come with multiple...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
6
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
11
by: PAul Maskens | last post by:
The form designer adds unnecessary code to the section when using a subclassed control. I've reproduced this in VS.NET 2002 and VS.NET 2003 so it's pretty fundamental. Outline steps: Create a...
16
by: devicerandom | last post by:
Hi, I am currently using the Cmd module for a mixed cli+gui application. I am starting to refactor my code and it would be highly desirable if many commands could be built as simple plugins. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.