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 catching 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 ...
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.
Read now
Unlock full access