The following doesn’t work for me in Java. Eclipse complains that there is no such constructor. I’ve added the constructor to the sub-class to get around it, but is there another way to do what I’m trying to do?
public abstract class Foo {
String mText;
public Foo(String text) {
mText = text;
}
}
public class Bar extends Foo {
}
Foo foo = new Foo("foo");
You can’t instantiate
Foosince it’s abstract.Instead,
Barneeds a constructor which calls thesuper(String)constructor.e.g.
Here I’m passing the
textstring through to the super constructor. But you could do (for instance):The
super()construct needs to be the first statement in the subclass constructor.