[Mono-list] Final method in C# (as the final keyword in Java)
Raja R Harinath
rharinath at novell.com
Tue May 30 07:20:26 EDT 2006
Hi,
Ympostor <ympostor at clix.pt> 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 guess it would've been slightly more informative if the compiler used
the CS0108 warning instead of CS0114).
- Hari
More information about the Mono-list
mailing list