Java |
By default, all methods are virtual.
class B {
public void foo () {}
}
class D extends B {
public void foo () {}
}
to hide a superclass method
declare it private or final
class B {
private void foo () {}
}
class D extends B {
public void foo () {}
}
|
|
C# |
The virtual keyword must be used so that the method
will be called by the base class.
class B {
public virtual void foo () {}
}
class D : B {
public override void foo () {}
}
using new to override a non virtual method.
class B {
public void foo () {}//hide from D
}
class D : B {
public new void foo () {}
}
|
|