Skip to content

Instantly share code, notes, and snippets.

@sourcerebels
Created April 4, 2012 14:26
Show Gist options
  • Save sourcerebels/2301727 to your computer and use it in GitHub Desktop.
Save sourcerebels/2301727 to your computer and use it in GitHub Desktop.
//Father.java
package test;
public class Father {
protected void hello() {
System.out.println("hello");
}
}
//Son.java
package test;
public class Son extends Father {
public void tellYourFatherSayHello() {
hello();
}
}
//StrangerSamePackage.java
package test;
public class StrangerSamePackage {
public void sayHello() {
Father f = new Father();
f.hello();
}
}
//SonOtherPackage.java
package other;
public class SonOtherPackage extends Father {
public void tellYourFatherSayHello() {
hello();
}
}
//StrangerOtherPackage.java
package other;
public class StrangerOtherPackage {
public void sayHello() {
Father f = new Father();
f.hello(); // COMPILATION ERROR
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment