Question which class method executes now ?

Niranjan

New member
Joined
Jul 28, 2015
Messages
1
Programming Experience
1-3
class BaseCls {
    public virtual void Show(int i) {
        Console.WriteLine(" BaseClsDisplay" + i);
    }

}

class childCls: BaseCls {
    public override void Show(int i) {
        System.Console.WriteLine("childClsDisplay" + i);
}


which class method executes now ? out childclsdisplay or Baseclassdisplay

if child class display method executed ok

then how to call Baseclsmethod

Please suggest me clear tutorial or explain

Thanks

Niranjan
 
Last edited by a moderator:
The whole point of overriding a method is to replace the functionality in the base class with new functionality in the derived class. If you have an object of type `childCls` and call Show on it then the derived implementation will be invoked. You don't call the base method from the outside. Inside the derived class, you can call `base.Show(i)` to invoke the base implementation. In fact, many overridden methods do just that in order to add to a base implementation rather than replace it altogether.
 
Back
Top Bottom