Lecture overview -- Keyboard shortcut: 'u'  Previous page: Overview of members in classes -- Keyboard shortcut: 'p'  Next page: Instance Methods -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 13 : 29
Object-oriented Programming in C#
Classes and Objects
Instance Variables

The individual state of objects are contained in instance variables. We illustrate instance variables by the owner, balance and interest rate of bank accounts. The exercise at the bottom of this page explores the visibility of the private instance across two or more instances of class BankAccount.

An instance variable defines a piece of data in the class. Each object, created as an instance of the class, holds a separate copy of the instance variables.

/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-0/bank-account.csInstance variables in the class BankAccount.


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-0/bank-account-client.csCreation of three bank accounts.


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-0/outputOutput from the BankAccount client program.


Three objects of class BankAccount, each holding three instance variables interestRate, owner, and balance. The values of variables are determined by the bank account transactions that we programmed in the class BankAccountClient. The state of the variables is shown relative to the three WriteLine calls.

Go to exerciseHow private are private instance variables?
Read more about instance variables in the text book version of this material.