my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Inheritance and constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance and constructors" Watch "Inheritance and constructors" New topic

Inheritance and constructors

Gina Ruffolo-Daniel

Joined: Oct 01, 2005
Posts: 19
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,
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9044
Loan does not have a no-arg constructor, so PersonalLoan cannot inherit what does not exist.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Rob Spoor

Joined: Oct 27, 2005
Posts: 19672

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(...).

How To Ask Questions How To Answer Questions
Gina Ruffolo-Daniel

Joined: Oct 01, 2005
Posts: 19
Thank you both for your help!
Don't get me started about those stupid light bulbs.
subject: Inheritance and constructors