-2

Can someone tell me why I'm getting the error Cannot find symbol when I'm creating an object? in bank_account Christine = new bank_account();

public class BankAccountTester
{
public static void main (String []args)
{
bank_account Christine = new bank_account();



Christine.deposit(10000);
Christine.withdraw(2000);


System.out.println(Christine.getBalance());
}
}

this is my class

public class bank_account{

private double balance;

public bank_account()
{
balance = 0;
}

public bank_account (double initialBalance)
{
balance = initialBalance;
}

public void deposit(double amount)
{
balance = balance + amount;
}

public void withdraw (double amount)
{
balance = balance - amount;
}

public double getBalance()
{
return balance;
}
}

1 Answers1

0

The program is fully functional, I've tried your code and it works fine. This is your compact code: https://gist.github.com/anonymous/8f055d981b27de4ce75c8c64d9a58498

Just go on www.compilejava.net and 'compile and run' it there. It works on compilejava.net and on my netbeans too. I think there's a problem with your compiler. You can try to reset it or even clean the cache: Deleting this directory should clear the cache for you- C:\Users\username.netbeans\7.0\var\cache //adapt with your version

An other error could be in creating project. In netbeans you have to create a project for each app you're developing. Have you did it and connected the 2 file of the program?

  • Well yeah, maybe because you put all code in the same file. Obviously, there is some import missing in the OP's code. Surely not a problem with the compiler. – oarfish Jun 19 '16 at 13:43
  • Not a problem a split code. On my netbeans the code is not in the same file. Maybe an error creating the project – Antony Zappacosta Jun 19 '16 at 13:51
  • Because you put both classes into the same package. There is no indication that OP has the same package structure. Also: [Are "Your code works fine for me" answers acceptable?](http://meta.stackoverflow.com/q/277923) – Tom Jun 19 '16 at 14:02
  • That was to prove that there were no problems in the code. I also tried the placing code in different files and compiling them on netbeans. Everything works; I think the problem is not having included the files in the same NetBeans project – Antony Zappacosta Jun 19 '16 at 14:09
  • Place them in different packages without using an import statement, then try it again ... – Tom Jun 19 '16 at 14:46