Raja R Harinath escribió:
Hi,
Ympostor <[EMAIL PROTECTED]> writes:
Simple question (forgive my ignorance):
public abstract class GrandFather
{
public abstract void DontOverrideMe();
}
public class Father : GrandFather
{
public sealed override
void DontOverrideMe()
{
Console.WriteLine("I am acting as a father");
}
}
public class Son : Father
{
public void DontOverrideMe()
{
Console.WriteLine("I am an unruly son");
}
}
Why the compiler only gives a warning about Son::DontOverrideMe instead
of an error? And why with a "new" keyword the warning disappears? I want
a non overridable method :(
You have a non-overridable method (hint: try using 'override' in 'Son').
I can't override the method in Son with the override keyword, but
without that keyword I can hide it! So I suppose that doing this:
Son oSon = new Son();
Son.DontOverrideMe();
The result would be "I am an unruly son".
I don't want that, I want that all derived classes of Father return "I
am acting as a father" to the console, and I want the compiler to
complain if a derived class wants to hide or override the method.
Did I clarify things a bit more? Thanks for your response Raja.
Regards.
--
_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list