Introduction to Computer Science

Start Lecture #12

Remark: reviewed practice midterm

Homework: UML diagrams are not required for all homework. 8.1, 8.3 (all ch 8 problems are at the 7th floor front desk of 715 bway.)

A static method (also called a class method) is associated with the class as a whole; whereas a non-static method (called an instance method) is associated with an individual object. The Circle1 class has one instance method along with the two constructors.

Thus when the two Circle1 objects are created, each gets its own getArea() method.

In a like manner a field can be declared to be static (none are in this example) in which case it is called a class field and there is only one that is shared by all objects instantiated from the class. (An object instantiated from a class is often called an instance of the class).

A field not declared to be static is called an instance field and each object gets its own copy; changing one, does not affect the others.

Putting this together we see that when the main() class invokes getArea() it must specify which getArea() is desired, i.e., which object's getArea() should be invoked. So myCircle.getArea() invokes the getArea() associated with myCircle and hence when it mentions radius (an instance field) it gets the radius associated with myCircle.