0

I have a class, SpecialSavings, which extends SavingsAccount. The SavingsAccount class has a constructor with parameters:

SavingsAccount(double balance){
    this.savingsBalance = balance;
}

I have another class, SpecialSavings_Driver that attempts to create 2 SavingsAccount objects using the SavingsAccount default constructor:

public class SpecialSavings_Driver {
    public static void main(String[] args){
        SpecialSavings saver1 = new SpecialSavings(2000.00);
        SpecialSavings saver2 = new SpecialSavings(3000.0);
    }
}

Eclipse tells me "The constructor SpecialSavings(double) is undefined". I have read in some places that subclasses use the default constructor of the superclass if none is explicitly defined in the subclass. Can someone please explain why this is not working for me?

Rick
  • 61
  • 1
  • 6
  • "_default constructor with parameters_" LoL. A default constructor means no parameters. – dryairship May 07 '16 at 11:55
  • Constructors are **not** inherited (read [here](http://www.javaworld.com/article/2076204/core-java/understanding-constructors.html)) at all. So you must provide them. If no es defined, the compiler adds the default (non-arg) constructor. – PeterMmm May 07 '16 at 11:56
  • So, I accidentally put a typo by putting "default constructor" when I meant "constructor". Whoops. I have corrected it. To the person who marked this duplicate, I invite you to see that my question has nothing to do with default constructors. I have corrected it. Thank you to PeterMmm, the guy who actually read the question and answered it for me. – Rick May 07 '16 at 13:26

0 Answers0