/* 1) Base obj = new Derived();
* Untill and unless you've a method overridden
* in the derived class, whether or not you say "new method"
* in the derived class, the base class's
* method would get called.
*/
Salary objBaseDerSalary = new DerivedSalary() ;
MessageBox.Show("objBaseDerSalary.myMethod() " + objBaseDerSalary.myMethod());
/* 2) Derived obj = new Base();
* Gives compilation error, because the parent
* cannot be implicitely converted to the derived.
* DerivedSalary objBaseDerSalary1 = new Salary();
* MessageBox.Show("objBaseDerSalary.myMethod() " + objBaseDerSalary1.myMethod());
*/
/* 3) Derived obj = (Derived) new Base();
* Gives Runtime error "specified cast isn't valid"
* You cannot downcast a base class.
* DerivedSalary objTCBaseDerSalary = (DerivedSalary) new Salary();
* MessageBox.Show("objTCBaseDerSalary.myMethod() " + objTCBaseDerSalary.myMethod());
*/
/* 4) Derived obj = new Derived();
* obj.myMethod(); will always call the derived
* myMethod whether or not you say "new method"
* in the derived class.
*/
DerivedSalary objDerDerSalary = new DerivedSalary();
MessageBox.Show("objDerSalary.myMethod() " + objDerDerSalary.myMethod());
/* Conclusion:
* Its the declared object's method that will get called.
* Unless you override, the base class's method will get called,
* if you've declared the object to be of base class.
*/