Having trouble calling a subclass method

Right now I'm having trouble with 3 classes, the first one Teller is used to create new bank accounts, the second one is an abstract Account class, the third is a subclass of Account. I'm having problems inheriting the methods from my Account class to use in my subclasses. Here is the code:

Teller class:

publicboolean createNewAccount (String accountNumber,String accountType,String customerName, String customerPhone,double balance){

if (accountType.equals("sav")){

anAcct =new SavingsAccount(accountNumber, customerName, customerPhone, balance);

}

abstract Account class method which i'm attempting to invoke:

public Account(String accountNumber, String customerName,String customerPhone,double balance){

this.accountNumber = accountNumber;

this.customerName = customerName;

this.customerPhone = customerPhone;

this.balance = balance;

}

Account subclass:

publicvoid SavingsAccount(String accountNumber,String customerName, String customerPhone,double balance){

this.accountNumber = accountNumber;

this.customerName = customerName;

this.customerPhone = customerPhone;

this.balance = balance;

This is my first time using abstraction so I have no clue if this code is right or not, but an help would be greatly appreciated.

[1868 byte] By [Hungreya] at [2007-10-3 8:56:06]
# 1
Is it a class? Or constructor?Constructor doesn't have any return type indeed.And what kind of subclass method do you mean?
herusalima at 2007-7-15 4:06:19 > top of Java-index,Java Essentials,New To Java...
# 2

Well what I have listed are all constructors from classes. The first constructor is a method in a class called Teller which I am using to call a method in my subclass SavingsAccount. The second constructor is a method from my abstract class called Account. The third method is from my SavingsAccount class (a subclass of Account) which I am using to create the SavingsAccount object.

The error that I am getting occurs at

anAcct = new SavingsAccount(String accountNumber, String customerName, String customerPhone, double balance);

and it states that the "constructor SavingsAccount(String, String, String, double) is undefined"

I hope this clears it up a little. If not I apologize, I am just really confused on how to call subclass methods.

Message was edited by:

Hungrey

Hungreya at 2007-7-15 4:06:19 > top of Java-index,Java Essentials,New To Java...
# 3

If you have

public abstract class Account

{

protected Account(args)

{

//..do stuff

}

}

then you can do this

public class SavingsAccount extends Account

{

public SavingsAccount(args)

{

super(args);

//do other stuff

}

}

where super() refers to the constructor of the abstract Account class. Note that the call to super() must precede anything else in the subclass constructor.

Cheers, Jukka

duckbilla at 2007-7-15 4:06:19 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks, that looks like it works. Guess my problem was having to explicitly define the default constructor in the subclass. Thanks for all the help.
Hungreya at 2007-7-15 4:06:20 > top of Java-index,Java Essentials,New To Java...