I’m relatively new to programming so excuse me if I get some terms wrong (I’ve learned the concepts, I just haven’t actually used most of them).
Trouble: I currently have a class I’ll call Bob its parent class is Cody, Cody has method call Foo(). I want Bob to have the Foo() method as well, except with a few extra lines of code. I’ve attempted to do Foo() : base(), however that doesn’t seem to work like. Is there some simple solution to this?
You can override
Fooin the derived class and call the overridden base class implementation usingbase.Foo():Output of
new Bob().Foo():Constructors use a slightly different syntax to call the constructor in a base class, because they have the requirement that the base class constructor must be called before the constructor in the derived class: