Chapter 4
Discovering Inheritance, Polymorphism, and Interfaces
An object-based language is a language that encapsulates state and behaviors in objects. Java’s support for encapsulation (discussed in Chapter 3) qualifies it as an object-based language. However, Java is also an object-oriented language because it supports inheritance and polymorphism (as well as encapsulation). (Object-oriented languages are a subset of object-based languages.) In this chapter, I will introduce you to Java’s language features that support inheritance and polymorphism. Also, I will introduce you to interfaces, Java’s ultimate abstract type mechanism.
Building Class Hierarchies
We tend to categorize stuff by saying things like “cars are vehicles” or “savings ...
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