Extending classes

So, let’s say, I have classes ExternalClass, OutterClass and InnerClass in a sketch called TestProject:

public class ExternalClass{
  ExternalClass(){
    
  }
}

final static public class OutterClass{
  final static public class InnerClass extends ExternalClass{
    private String someValue;
    InnerClass(String someValue){
      super();
      this.someValue = someValue;
    }
  }
}

The console shows an error:

TestProject [11]: No enclosing instance of type TestProject is available due to some intermediate constructor invocation

What’s going on and how do I extend InnerClass by ExternalClass?

  • All classes & interfaces inside “.pde” files are nested within the sketch’s PApplet subclass.
  • And if they aren’t declared w/ the keyword static, they’re also called inner classes.
  • That means your class ExternalClass is actually an inner class.
  • And b/c it’s declared w/ static, OuterClass isn’t an inner class, but just a nested class, enclosed within a PApplet subclass.
  • For the same reason, InnerClass isn’t an inner class, but the OuterClass’s nested class.
  • As a workaround you can turn ExternalClass inner class to a nested 1 by declaring it w/ static.