Java Reference
In-Depth Information
CHAPTER
4
Classes and Objects
In the last two chapters, I discussed the fundamentals of the Java programming
language: keywords, primitive data types, references, strings, arithmetic oper-
ators, and control structures. We are now ready to discuss the most important
aspect of learning and understanding Java: object-oriented programming
(OOP). In this chapter, I will discuss classes and objects, how object-oriented
programs differ from procedural programs, how to write a class in Java, and
how to instantiate and use objects.
Overview of Classes and Objects
Java is strictly an objected-oriented programming language. All the Java code
that you write will appear in either a class or an interface. (Interfaces are dis-
cussed in Chapter 10, “Interfaces.”) When you write a program using an
object-oriented programming language, you design your program around the
objects in the problem being solved. For each object, a class is written to describe
the object's attributes and behaviors.
By definition, a class is a description of an object. Similarly, an object is
defined to be an instance of a class. An object consists of attributes and behav-
iors. An attribute is a feature of the object, something the object “has.” A
behavior is something the object “does.”
85
Search WWH ::




Custom Search