Concepts to be absorbed from  L9

Public & private

In the classes we wrote so far we have used only private instance variables, and all public methods. In l9 notes you see examples of situations where it is appropriate to have a public method calling a lower level "worker" method which is private. Follow the programs  Tunes.java and the Lotto class and make sure you understand the reasons for public and private methods.  You can download the programs and run them.

Co-operating objects

It is important to understand how objects are referenced in order to be able to write programs using co-operating objects. The exercises in page 11-13 are designed to get you to distinguish between the address of the object and the object itself.  Work through this simulating on paper what happens with the machine address. Note that it is possible to have more than one variable pointing to the same object.  If two variables are   holding the address of the same object (still only one object) than we can access that object's  public methods  using a prefix of either variable name.

On page 14 we take that concept a step further to see how a reference variable can be passed to a method thus allowing code in the method to access the methods of an outside   object.

This leads us into the important concept of how different objects can co-operate in a program. We can call a method of one class and pass to it a reference to an object from a different class. We can have as an instance variable in one class a reference to an object from a different class. Follow the example in page16-18 very carefully and  see how the docket class and the bankAccount class are related. Note the program RunBank uses the BankAccount class from chapter 8.

Importance of the above concepts

The project  which will be the final part of your practical assessment will require the application of the above concepts, so it is imperative that you understand them.

You will also notice in past papers some general questions relating to object oriented concepts - encapsulation etc. and this chapter is relevant here also. There are also questions on the exam paper involving a program comprised of a few interacting classes so after you have worked on this chapter you should be able to tackle them.

You will be glad to hear your lab exam in week 9 will not depend on them