开发者

Cannot find symbol error

开发者 https://www.devze.com 2023-03-01 05:56 出处:网络
I am writing some code that extends another class I developed for a programming assignment. However I keep getting stuck with one single error when I try to compile my program:

I am writing some code that extends another class I developed for a programming assignment. However I keep getting stuck with one single error when I try to compile my program:

CDAccount.java:11: cannot find symbol
symbol  : constructor BankAccount()
location: class BankAccount
        {
        ^

And the program is as follows:

import java.lang.IllegalArgumentException;

    public class CDAccount extends BankAccount
    {
            Person owner_;
            double balance_;
            double rate_;
            double penalty_;

            public CDAccount(Person Owner, double Balance, double Rate, double Penalty)
            {
                    if(Balance < 0)
                    {
                            throw new IllegalArgumentException("Please enter a positive Balance amount");
                    }
                    else
                    {
                            if(Rate < 0)
                            {
                                    throw new IllegalArgumentException("Please enter a positive Interest Rate");
                            }
                            else
                            {
                                    if(Penalty < 0)
                                    {
                                            throw new IllegalArgumentException("Please enter a positive Penalty amount");
                                    }
                                    else
                                    {
                                            if(Owner.equals(null))
                                            {
                                                    throw new IllegalArgumentException("Please define the Person");
                                            }
                                            else
                                            {
      开发者_如何学Go                                              owner_ = Owner;
                                                    balance_ = Balance;
                                                    rate_ = Rate;
                                                    penalty_ = Penalty;
                                            }
                                    }
                            }
                    }
            }
    }


Your CDAccount constructor neesd to call the super class constructor as it's first statement. If you don't explicitly put

super();

as the first line, then the compiler will insert

super();

for you (invisibly).

However your BackAccount class apparently doesn't have a constructor that takes no parameters, so either add a constructor that does, or explicitly add a call to the super class with parameters that you have a constructor for like

super(owner);

or whatever you want to pass to the super class.

0

精彩评论

暂无评论...
验证码 换一张
取 消