• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance and constructors

 
Gina Ruffolo-Daniel
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created an abstract class that uses a constructor to provide data and a method that a subclass can inherit. My subclass is stating that the abstract class's constructor is not being inherited. Here is my code. Parent class

Child Class


Thank you in advance,
Gina
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loan does not have a no-arg constructor, so PersonalLoan cannot inherit what does not exist.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually constructors are never inherited. If class Loan has a constructor with a set of parameters, and you need a constructor in PersonalLoan with the same set of parameters, you must implement it all over (and call super(...)); it isn't there "magically" like inherited methods are.

The thing with constructors is, they always call super() as the first line unless you specify another super() constructor to call or a call to this(...).
 
Gina Ruffolo-Daniel
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for your help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic