0

In eclipse, when I create a base class with argument based constructor, all derivatives of that class are forced to call super constructor. Else it does not seem to be needed. Why is this? I'm guessing that derivative classes always call super() in their constructor by default even if I don't mention that. Could someone clarify this for me? thank you in advance.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
Horse Voice
  • 8,138
  • 15
  • 69
  • 120

1 Answers1

1

When you define your own constructor,the compiler does not provide a no-argument constructor for you. When you define a class with no constructor,the compiler inserts a no-arg constructor for you with a call to super().

class Example{
}
becomes

class Example{

Example(){
super();   // an accessible no-arg constructor must be present for the class to compile.
}

However,it is not the case with your base class with a argument constructor as the compiler cannot find a no-arg constructor for base class.You need to explicity define a constructor for you with a call to any of the super constructor

Kumar Abhinav
  • 6,565
  • 2
  • 24
  • 35