A
Adrian Herscu
Think again. *Only* non-virtual methods can be "hidden".
Base::Foo is clearly declared virtual, but it is not really virtual !
If it were virtual then:
Base b = new Derived();
b.Foo();
would output:
Derived.Foo
That's exactly the semantics of being non-virtual.
And again, "final" in Java is very different from non-virtual - a
non-virtual method can be hidden, but a "final" method cannot be hidden.
Not sure where you get that from:
using System;
class Base
{
public virtual void Foo()
{
Console.WriteLine ("Base.Foo");
}
}
class Derived : Base
{
public new void Foo()
{
Console.WriteLine ("Derived.Foo");
}
}
public class Test
{
static void Main()
{
Base b = new Derived();
Derived d = new Derived();
b.Foo();
d.Foo();
}
}
Base.Foo is clearly a virtual method, but as far as I can see
Derived.Foo hides it in exactly the same way as if it were non-virtual.
Take away the keyword "new" and you get a warning:
Base::Foo is clearly declared virtual, but it is not really virtual !
If it were virtual then:
Base b = new Derived();
b.Foo();
would output:
Derived.Foo
That's exactly the semantics of being non-virtual.
And again, "final" in Java is very different from non-virtual - a
non-virtual method can be hidden, but a "final" method cannot be hidden.