I am getting the following errors when I try to compile this: thoughts?

_______________________________________________________________________
BankAccount.java:11: <identifier> expected
public BankAccount(String, double, double)
^
BankAccount.java:25: ')' expected
public abstract void updateBalance();
^
2 errors

___________________________________________________________________

protected abstract class BankAccount
 {
  public BankAccount(String, double, double)

  	{
		String accountID;
		double balance;
		double interest;
	}

  public String getAccountID()

  	{
		return accountID;
	}

  public abstract void updateBalance();

  	//{
	//	return balance;
	//}

  public String toString()

    {
		String result;

		result = ("\n" + "Account ID:\t\t" + accountID + "\n"
			     + "Balance:\t\t" + "$" + balance + "\n"
			     + "Interest:\t\t" + interest + "%" + "\n");

		return result;
	}
  }

Recommended Answers

All 4 Replies

Well, first of all, is this all your program?

2nd. From what I can see, you stated your variables inside your constructor.
State your variables outside of your constructor.Then, initialize your variables inside the constructor.

protected abstract class BankAccount
      {
          String accountID;
           
          double balance;
       
          double interest;
      public BankAccount(String a, double b, double i)     {
      this.accountid=a;
this.balance=b;
this.interest=i;
      }

I forgot what protected means but I think you can only access it through a specific way. When I pasted your code on eclipse, it said that if your using abstract, you cant use protected. Only public, final and abstract are permitted.

ERROR #1:
In your constructor:

public BankAccount(String a, double b, double c)//You need to assign a variable to each type otherwise nothing is storing the value and it won't compile
{
 
}

ERROR #2:

#
public abstract void updateBalance();
{ //You need to un-comment the braces and close this method

// return balance;

}

Is the ^ underneath the same letter in your posted message as when output by the compiler?

public BankAccount(String, double, double)

I suspect that the compiler was pointing to the list of args to the constructor.
All the args need variable names.

When I pasted your code on eclipse, it said that if your using abstract, you cant use protected. Only public, final and abstract are permitted.

Thats what happens when you rely too much on your IDE to tell you the errors. ;)

@ O.P.
Read up on your Access Modifiers, a class can have only default access or public, if you read up on private and protected you will figure out why they dont make sense for a class.

@Akill10
Your solution to Error#2 is incorrect, note the method is declared as abstract so it cannot have a body. I too agree with NormR1 on that one, the second error seems more like a side effect of the first one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.