Quote:
i can do it by creating derivd class instance. and declaring base class method as sealed.
If you do that, you cannot create a derived class - a
sealed
class is one that specifically
cannot be used as a base, it cannot be inherited from.
Quote:
it will called base class as well as derived class methods.
No, it won't: Because you have overridden the base class method, it will call the "latest" method.
And if you do this:
Derived d = new Derived();
d.SomeMethod();
Base b = new Base();
b.SomeMethod();
b = d;
b.SomeMethod();
It will call the Derived method, then the Base method, then the Derived method.
The
virtual
keyword tells the compiler that a derived class
can override the method. If you omit it, you can't use
override
in the derived class method definition.