Sarica Ivic

Greenhorn
+ Follow
since Jan 26, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sarica Ivic

Thanks everyone...
So conclusion would be:ChildInDifferentPackage can acess parent's public and protected static methods.
And child also gets those methods through inheritance...
And child does not see parent's private and default static methods nor gets them through inheritance.
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