1

I have a class that extends another class. I need to run additional code in the constructor of my child class. How do I do this?

//MyClass.class
//This is what i want to do
public class MyClass extends BaseClass {
    constructor() {
        super(); // EDIT (thanks)
        // stuff?
    }
}

Please help.

dopatraman
  • 11,801
  • 22
  • 74
  • 138

2 Answers2

2

should be:

/MyClass.class
//This is what i want to do
public class MyClass extends BaseClass {
    MyClass() {
        super(); // no need for constructor here, just super()
        // stuff?
    }
}
Nir Levy
  • 11,751
  • 3
  • 18
  • 36
0

Simply call super(). This will call the super class's constructor. See Can an abstract class have a constructor?

Community
  • 1
  • 1
Alex Loper
  • 125
  • 10