Is a virtual method compulsory to override by its subclass?
Is a virtual method is compulsory to override by it's sub class?
No.
Can I Override a method which is NON-Virtual in parent class ?
No.
What is YES then ?
You must implement Abstract method of parent class (if derived class is non-abstract)
Can I write Virtual keyword on Static method
NO, Because these two are just opposite words. Virtual means compiler does not know at compile time which method to be called. Static means , for sure , your compiler knows which method will be called.
How do I stop my current class' subclasses to no Override my method ?
Mark it with sealed keyword.
Is Abstract method a virtual also ?
YES. That's why we cant explicitly mark abstract method virtual as well.
Is Override and Overload same ?
Off-course not! Overloading is having 2 methods with same name but which works on different set of input parameters.
When shall I Mark a method as Virtual ?
When you are using polymorphism and you are not sure about the type of the object passes to your method until runtime, and you want your subclasses to have different behavior then mark the method as Virtual. e.g. You have
class Law
{
public void Punish(Minister any)
{
if (any.Corruption() == true)
{
... do whatever public wants...
}
}
}
And you have Hierarchy of Minister classes -Ministers, CentralGOVTMinisters , StateGOVTMinisters , DistrictAuthorityMinisters etc. And you know that Whatever defined in Minister class for Corruption() method can be used by many derived class but for few ministers Corruption laws are different (they have supreme powers may be !) , so there you override the Corruption() and everywhere else your derived classes use the implementation of Corruption() in Minister class (base of all minister).