Why doesn't override hide parent methods???

B

Bob Rock

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
J

Jon Skeet [C# MVP]

Bob Rock said:
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.
 
B

Bob Rock

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.

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
 
J

Jon Skeet [C# MVP]

Bob Rock said:
Ok, here is the code:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top