Chapter 4. Classes and Objects

WITH the knowledge you now have of the basics of the Java programming language, you can learn to write your own classes. In this chapter, you will find information about defining your own classes, including declaring member variables, methods, and constructors.

You will learn to use your classes to create objects and how to use the objects you create.

This chapter also covers nesting classes within other classes, enumerations, and annotations.

Classes

The introduction to object-oriented concepts in Chapter 2 used a bicycle class as an example, with racing bikes, mountain bikes, and tandem bikes as subclasses. Here is sample code for a possible implementation of a Bicycle class, to give you an overview of a class declaration. ...

Get The Java™ Tutorial Fourth Edition: A Short Course on the Basics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.