Things to keep in mind:
#1- Static methods are not overridden but that can be redefined that is
happening in original post.
#2- Non static methods can be overridden provided they are not final and
visible to the subclass (not private of course).
Scenario with the original question:
3- When you create subclass object from the main method, you see in both
the constructors there is call to the method. See point #1, so from the
parent class constructor its own addValue() method will be called. And from
the Derived class, its own addValue() method, resulting value 30.
Scenario when you remover static from both the methods:
In one
word "POLYMORPHISM"
4- You created object of Derived class, then from the Base class addValue()
will be the overridden version not of the Base class; this is called
"run time method selection". From the Derived class the method be obviously
its own, resulting result 40.
Note: If you don't explicitly insert call to super() or this() in the
constructor the compiler automatically inserts super();
Thanks,