I am new to Java, could you please tell me - "what is the purpose of the protected variable and method in Java".
Thanks in advance.
JP.
I am new to Java, could you please tell me - "what is the purpose of the protected variable and method in Java".
Thanks in advance.
JP.
Take a look at the docs
The following table shows the access to members permitted by each modifier.
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 a Java application will be accessible form subclasses, class itself AND classes in the same package!, knowing this, you should use protected
when some methods or attributes of one class needs to be shared around.