Java Reference
In-Depth Information
Chapter 3
Classes
OBJECTIVES
• Discuss the class definition as a template for its instances (folders).
• Discuss information hiding for fields, but show when public fields are useful.
• Show how the inside-out rule is used in Java.
• Define the constructor and show how it is used.
• Compare testing of folder names with testing of their contents.
• Show when to make a method or field static.
• Discuss object-oriented design.
• Look at a model of execution.
INTRODUCTION
Chapter 1 introduced classes. You saw the use of class JFrame and the creation
and use of at least one subclass of class JFrame . In this chapter, we provide an in-
depth discussion of classes, reviewing the concepts introduced in Chap. 1 and
introducing the rest of the concepts needed to understand and use classes.
3.1
Class definitions
Figure 3.1 contains the definition of a class Employee . There are a few new things
in this class, which we explain below.
An instance of this class represents a person in a company, with a name, the
year they were hired, and a starting salary of $50,000. In a real program, an
instance would contain more information —the person's address, social security
number, and so on. We maintain only three pieces of information in an instance
in order to keep the class manageable in this discussion.
A similar class
is discussed in
activity 3-6.1
Search WWH ::




Custom Search