Skip to Content
Java in a Nutshell, 7th Edition
book

Java in a Nutshell, 7th Edition

by Benjamin J. Evans, David Flanagan
December 2018
Intermediate to advanced
458 pages
12h 18m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 7th Edition

Chapter 3. Object-Oriented Programming in Java

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 programming 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.

Note

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 cannot write Java code without defining a class. All Java statements appear within classes, and all methods are implemented within classes.

Basic OO Definitions

Here are a couple important definitions:

Class

A class is a collection of data fields that hold values and methods that operate on those values. A class defines a new reference type, such as the Point type defined in Chapter 2.

The Point class defines a type that is the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Head First Java, 2nd Edition

Head First Java, 2nd Edition

Kathy Sierra, Bert Bates
Head First Java, 3rd Edition

Head First Java, 3rd Edition

Kathy Sierra, Bert Bates, Trisha Gee

Publisher Resources

ISBN: 9781492037248Errata Page