Lecture overview -- Keyboard shortcut: 'u'  Previous page: Instance Variables -- Keyboard shortcut: 'p'  Next page: Class Variables -- 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 14 : 29
Object-oriented Programming in C#
Classes and Objects
Instance Methods

An instance method is always activated on an object. An instance method can can access instance variables as well as class variables.

An instance method is an operation in a class that can read and/or modify one or more instance variables.

  • An instance method M in a class C

    • must be activated on an object which is an instance of C

    • is activated by object.M(...) from outside C

    • is activated by this.M(...) or just M(...) inside C

    • can access all members of C

 

/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-0/bank-account.csThe BankAccount Class.

In this version of class BankAccount we have emphasized five instance methods.

/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-3/bank-account-client.csSelected messages to BankAccount methods from a client class.

The activation of the methods represent messages from Main to individual bank account objects.

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


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-3/bank-account.csMethods in the - slightly extended - class BankAccount.

A version of class BankAccount with transaction logging. This version of the class is the basis for the exercise below.

Go to exerciseThe method LogTransaction in class BankAccount
Go to exerciseCourse and Project classes
Read more about instance methods in the text book version of this material.