Hello from Java Junior
Scenario:two classes (super class and subclass) in different packages.
Super class has two protected methods,static and nonstatic method.
Subclass using reference on superclass can "see" protected static method but cannot see non static protected method...
package scjp.staticPlusProtected.package1;
public class Country {
protected static void protectedAndStaticMethod(){}
protected void protectedButNotStatic(){}
}
package scjp.staticPlusProtected.package2;
import scjp.staticPlusProtected.package1.Country;
public class Croatia extends Country {
public static void main(){
Country cr=new Country();
cr.protectedAndStaticMethod();// compiler says OK WHY??
cr.protectedButNotStatic();//---->error..I expected that....The method from the type Country is not visible
Croatia croatia=new Croatia();
Croatia.protectedAndStaticMethod();//OK...static protected member is inherited
croatia.protectedButNotStatic();//OK protected member is inherited
}
So why is it possible to see static protected method of class that is in different package??Thanks