wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance and constructors" Watch "Inheritance and constructors" New topic
Author

Inheritance and constructors

Gina Ruffolo-Daniel
Greenhorn

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,
Gina
Marilyn de Queiroz
Sheriff

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


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

Joined: Oct 27, 2005
Posts: 19656
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Gina Ruffolo-Daniel
Greenhorn

Joined: Oct 01, 2005
Posts: 19
Thank you both for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance and constructors
 
Similar Threads
Format the output
Arrays
Trouble with loan calculator program
Help with errors again
Newbie Question : cannot resolve symbol : variable