8.1 Introduction
We now take a deeper look at building classes, controlling access to members of a class and creating constructors. We show how to throw
an exception to indicate that a problem has occurred—Section 7.5 discussed catch
ing exceptions. We use the this
keyword to enable one constructor to conveniently call another constructor of the same class. We discuss composition—a capability that allows a class to have references to objects of other classes as members. We reexamine the use of set and get methods. Recall that Section 6.10 introduced the basic enum
type to declare a set of constants. In this chapter, we discuss the relationship between enum
types and classes, demonstrating that an enum
type, like a class, can be declared in its ...
Get Java How to Program, Early Objects, 11th Edition 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.