what is the purpose of protected variable and method in java -
this question has answer here:
i new java, please tell me - "what purpose of protected variable , method in java".
thanks in advance.
jp.
take @ docs
following table shows access members permitted each modifier.
access levels
modifier class package subclass world public y y y y protected y y y n no modifier y y n n private y n n n
so, protected elements in java application accessible form subclasses, class , classes in same package!, knowing this, should use protected
when methods or attributes of 1 class needs shared around.
- if don't want leaking of internal state, declaring member variables private way go.
- if don't care subclasses can access internal state, protected enough.
Comments
Post a Comment