Now that we've covered fundamental Java syntax, we are ready to begin object-
oriented programming in Java. All Java programs use objects, and the type of an
object is defined by its class or interface . Every Java program is defined as a class,
and nontrivial programs include a number of classes and interface definitions. This
chapter explains how to define new classes and how to do object-oriented program‐
ming with them. We also introduce the concept of an interface, but a full discussion
of interfaces and Java's type system is deferred until Chapter 4 .
If you have experience with OO programming, however, be
careful. The term “object-oriented” has different meanings in
different languages. Don't assume that Java works the same
way as your favorite OO language. (This is particularly true
for C++ or Python programmers).
This is a fairly lengthy chapter, so let's begin with an overview and some definitions.
Overview of Classes
Classes are the most fundamental structural element of all Java programs. You can‐
not write Java code without defining a class. All Java statements appear within
classes, and all methods are implemented within classes.
Basic OO Deinitions
Here are a couple important definitions: