The nested class Embryo is implicitly static in an interface.
As such, it does not have access to the virtually invokable method bear, which would pertain to instances of your Mother interface.
Therefore:
- Either you declare
Mother as interface, then your Embryo's ecluse method cannot virtually invoke bear because it's statically-scoped
- Or, you keep
Mother as an abstract class, but require an instance of a Mother (anonymous or a child class' instance) in order to get an instance of Embryo (but Embryo is instance-scoped unless specified otherwise, and can invoke bear virtually)
Self-contained example
package test;
public class Main {
public interface MotherI {
// this is static!
public class Embryo {
public void ecluse() {
// NOPE, static context, can't access instance context
// bear(this);
}
}
// implicitly public abstract
void bear(Embryo e);
}
public abstract class MotherA {
public class Embryo {
public void ecluse() {
// ok, within instance context
bear(this);
}
}
public abstract void bear(Embryo e);
}
// instance initializer of Main
{
// Idiom for initializing static nested class
MotherI.Embryo e = new MotherI.Embryo();
/*
* Idiom for initializing instance nested class
* Note I also need a new instance of `Main` here,
* since I'm in a static context.
* Also note anonymous Mother here.
*/
MotherA.Embryo ee = new MotherA() {public void bear(Embryo e) {/*TODO*/}}
.new Embryo();
}
public static void main(String[] args) throws Exception {
// nothing to do here
}
}