|
-
February 6th, 2001, 12:09 PM
#1
new Keyword
The C# language asks foe a "new" keyword when I derive an interface "IDerived" from interface "IBase" and the function "getName()" is declared in both Interfaces. Does this mean , that C# doesnot allow method overridding.
Java Developer
SRG Systems Inc.
CT, USA
-
February 9th, 2001, 12:58 AM
#2
Re: new Keyword
C# supports virtual functions overriding. But by default your IDerive.getName() isn't an override of your IBase.getName(). It's a NEW virtual function although it has the same name. The compiler warns you. If you specify explicitly that IDerive.getName()is a new virtual function by using the new keyword it will stop warn you. But if you want IDerive.getName()to be an override of IBase.getName()you MUST use the override keyword.
public interface IBase
{
public virtual getName();
}
public interface IDerive: IBase
{
public override virtual getName();
}
-
February 13th, 2001, 05:48 AM
#3
Re: new Keyword
Actually, the distinction is as follows.
If you want polymorphism, then you need to use the virtual/override keyword pair as you suggested.
However, if you simply want to supply a new (overridden) version of the method, then you need only define the method as new.
Cheers,
Tom Archer - CodeGuru
Inside C# (early 2001)
Teach Yourself Visual InterDev in 24 Hours
------
Tom Archer, Archer Consulting Group Inc.
Author - Inside C#, Visual C++.NET Bible, Extending MFC Apps with .NET
http://www.ArcherConsultingGroup.com
Consulting * Training * Custom Development * Enterprise Solutions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|