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

Why doesn't override hide parent methods???

Hello,

I've noticed that in a child class that is overriding the parent's abstract
class methods, these abstract methods are still available.
Is this behavior correct??? Shouldn't overriden methods be hidden and be
accessible only through the base keyword??? In my case since the base class
and methods are abstract it would really be nice if abstract methods were
hidden in implementing classes.
Thx.
Bob Rock

Nov 16 '05 #1
4 1669
Bob,

Why would they be hidden? The whole point of abstract methods is that
they force a definition to be made in the base class. If you didn't allow
abstract methods to be implemented, you could never have a concrete class
definition.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bob Rock" <no***************************@hotmail.com> wrote in message
news:OS**************@TK2MSFTNGP10.phx.gbl...
Hello,

I've noticed that in a child class that is overriding the parent's abstract class methods, these abstract methods are still available.
Is this behavior correct??? Shouldn't overriden methods be hidden and be
accessible only through the base keyword??? In my case since the base class and methods are abstract it would really be nice if abstract methods were
hidden in implementing classes.
Thx.
Bob Rock

Nov 16 '05 #2
Bob Rock <no***************************@hotmail.com> wrote:
I've noticed that in a child class that is overriding the parent's abstract
class methods, these abstract methods are still available.
Is this behavior correct??? Shouldn't overriden methods be hidden and be
accessible only through the base keyword??? In my case since the base class
and methods are abstract it would really be nice if abstract methods were
hidden in implementing classes.
Thx.


I suspect you're not seeing what you think you're seeing.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
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
> I suspect you're not seeing what you think you're seeing.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

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


Ok, here is the code:

public abstract class AbsClass
{
public abstract void MyMethod();
}

public class ConcClass : AbsClass
{
public override void MyMethod()
{
// implementation
}
}

public class StartupClass
{
public static void Main()
{
ConcClass c = new ConcClass();

// when writing the following line intellisense displays two
MyMethod() methods (AbsClass.MyMethod() and ConcClass.MyMethod())
c.MyMethod();
}
}

As I said, intellisense displays two MyMethod() methods, AbsClass.MyMethod()
and ConcClass.MyMethod(), although I don't see how I could "select" the one
on AbsClass.
Anyhow, I thought that I would be able to see only the concrete one (I
expected the base class method to be hidden by the concrete class override),
but apart this I don't see the sense in displaying the one on the abstract
class.

Bob Rock

Nov 16 '05 #4
Bob Rock <no***************************@hotmail.com> wrote:
I suspect you're not seeing what you think you're seeing.

Could you post a short but complete program which demonstrates the
problem?
Ok, here is the code:


<snip - thanks>
As I said, intellisense displays two MyMethod() methods, AbsClass.MyMethod()
and ConcClass.MyMethod(), although I don't see how I could "select" the one
on AbsClass.
Anyhow, I thought that I would be able to see only the concrete one (I
expected the base class method to be hidden by the concrete class override),
but apart this I don't see the sense in displaying the one on the abstract
class.


Ah, so it's really just an Intellisense issue? Sorry, that wasn't clear
from your first post. Yes, this does indeed look like a bug in
Intellisense. It doesn't affect the compiler or the language though.
Best just to ignore it, really.

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

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

Similar topics

5
by: Steve | last post by:
Visual Studio 2003 C# Windows: I have a tree view control as my main menu control down the left side of my application. This has 2 Parent Nodes on it (Jobs and Employees). beneath these 2 main...
4
by: Néstor Marcel Sánchez Ahumada | last post by:
In a method declaration the 'sealed' keyword must be used with the 'override' keyword to avoid further overriding. Thus it can't be used in base classes. Why? This would be a good enhancement for...
9
by: Ken Varn | last post by:
Is there anyway to override a public virtual method or property so that it is private in my derived class? I tried using new on the property and making it private, but no luck. --...
5
by: Mark Broadbent | last post by:
Oh yes its that chestnut again! Ive gone over the following (http://www.yoda.arachsys.com/csharp/faq/ -thanks Jon!) again regarding this subject and performed a few of my own tests. I have two...
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
3
by: Tom Jones | last post by:
I do not understand what is meant when someone states that a given method is "hidden" verses overriden. Would someone please provide a short example of both cases and why you might want to...
5
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This...
14
by: Dave Booker | last post by:
It looks like the language is trying to prevent me from doing this sort of thing. Nevertheless, the following compiles, and I'd like to know why it doesn't work the way it should: public class...
2
by: Your_Persona | last post by:
Is there a way to get effect1 with the method in effect2? ///////////////////////////////////////////////////////////////////////////////////////////// using System; using...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.