What are Instance Variables...

  1. So far, we have the following design for BankAccount:

    class BankAccount { ... what kind of variables ? (answered below !) public void deposit(double amount) // to deposit money into account { ... (later) } public void withdraw(double amount) // to withdraw money from account { ... (later) } public double getBalance() // to retrieve balance of account { ... (later) } }

  2. Instance variables are non-static variables in a class.

  3. Why do you need Instance variables ?

    Object must store its state in a set of variables.

  4. What is state:

    The state of an object is a set of values that describe the current disposition of the object.

  5. Example: Bank Account.

    Question: what value or values can describe the state of a bank account so that the methods:

    can get their job done ???
    (What do you need to know to perform a "deposit(2000)" operation ???)

    See the answer here: click here