Chapter 11
The focus in chapter 11 is on how to create an entire class. Up to this point students have only
been adding methods to existing classes. We think that this allows the students to focus on
learning basic concepts without the added overhead of how to create a class. Many introductory
In section 11.1 we talk about how to identify the objects and classes in a program. This is a very
useful exercise for students and it is helpful for them to try to do this in many contexts. You
could ask them to identify objects and classes in many different situations such the objects
involved in a visit to a movie theater, the objects involved in getting money from an ATM
machine, and the objects involved in putting on a play. Often it is fun to tell students the
In section 11.2 we show how to define a class including defining fields. An important thing to
point out is that each object “knows” what class created it since it keeps a reference to the Class
object that defines that class. By creating a simple class with just some fields we can show the
power of inherited methods and introduce overriding inherited methods. We next show creating
a constructor and explain that if your class didn’t provide a constructor the compiler created one
In section 11.3 we show that you can overload constructors as long as the parameter list is
different. Again you can use a debugger to check which method is called.
In section 11.4 we show creating and initializing an array. Even though we introduce the
concept of an array early we don’t really have students working directly with arrays until this
chapter. We find the average of an array of grades to show processing an array. We continue to
show how to use a debugger to trace execution.
In section 11.5 we introduce getter and setter methods and the purpose of making the data private
but allowing public getters and setters. It is important to point out that objects should protect
their data. One way to underscore this is to ask a student what his or her name is and then tell
You can also talk about bank accounts and that the amount in your account should be private but
you should have a way to add and remove money from the account. Students don’t usually
understand why we make fields private until we show that other classes can reach in and change
the data if it is public. They still don’t usually understand that one object of a class can reach in