mohitkumar gupta wrote:
then,addValue method of Base class would be called as static methods are not overriden and in case of static methods reference type determines which method to call value=10
then addValue method call in Derived class constructor would be called therefore value=10+10=20
Those are different stuffs. When you are creating the Derived class object, the compiler doesn't care about, to what reference type variable you are going to assign this object. Assigning to a super type, doesn't make any impact on the creation of the object. Only after creating the object, you are going to assign it.
And, make the method as instance methods, and predict the output. It should be 40.