When I try running this piece of code, it gives me 30. Can someone please explain!I know you can't override static methods in Java, because, polymorphism and static won't work together. And static methods are invoked on Class, not in instances. but can someone please explain further on this topic. I don't really understand why i am getting a 30 and not 10. thanks!
class One {
static int value = 0;
One(){
addValue ();
}
static int addValue () {
return value+=10;
}
int getValue () {
return value;
}
}
class Two extends One {
Two () {
addValue ();
}
static int addValue () {
return value+=20;
}
public static void main(String[] args ) {
One t = new Two ();
System.out.println(t.getValue());
}
}