Jeroen De Dauw Jeroen De Dauw - 1 year ago 149
Java Question

Default constructors in Java

I know I'm asking some serious 101 question here...

I have some class

and a class
that extends
. In
I have a constructor that takes a set of parameters that it sets to its fields. Deriving classes such as
will typically not need to modify this. Now my IDE is giving me "There is no default constructor available in Foo". From a bit of Googling this appears to be because "constructors are not inherited". So all nice and well, but how do I now get this to work without duplicating this constructor in every deriving class? I'm assuming there is a more sane approach?

Answer Source

Use the super constructor:

public Bar(int a, double b, ...) {
    super(a, b, ...);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download