How could I create a method in a given class that can only be called internally by it, and its subclasses.
For example, the class Foo:
public class Foo{
public Foo(){
}
???? void bar(){
}
}
and the class Baz, extending Foo:
public class Baz extends Foo{
public Baz(){
this.bar(); //valid
}
}
but also, some other random class, Qux:
public class Qux{
private Baz baz = new Baz();
public Qux(){
baz.bar(); //invalid
}
}
note that any of these classes could be in any package, so a simple 'protected' wont work.
if this isn't possible with a keyword or something similar, i'm open to suggestions on how to achieve similar behavior.