scjp - What does redefining static methods mean in Java? -
scjp - What does redefining static methods mean in Java? -
i've been reading section on statics in scjp study guide, , mentions next :
static methods can't overridden, can redefined
what redefining mean? case of having static method exists in both parent , child, same signature, referenced separately class names? such :
class parent { static void dosomething(string s){}; } class kid extends parent { static void dosomething(string s){}; } referenced : parent.dosomething(); , child.dosomething(); ?
also, same apply static variables, or static methods?
it means functions not virtual. example, have object of (runtime) type kid referenced variable of type parent. if invoke dosomething, dosomething method of parent invoked:
parent p = new child(); p.dosomething(); //invokes parent.dosomething if methods non-static, dosomething of kid override of parent , child.dosomething have been invoked.
the same holds static fields.
java scjp
Comments
Post a Comment