Inheritance in Java, Part 1: The extends keyword
Java supports class reuse through inheritance and composition. This two-part tutorial teaches you how to use inheritance in your Java programs.
What you'll learn in this Java tutorial
The first half of this introduction to Java inheritance teaches you how to use the extends
keyword to derive a child class from a parent class, invoke parent class constructors and methods, and override methods:
- What is inheritance in Java?
- Single inheritance and multiple inheritance
- How to use the extends keyword in Java
- Understanding Java class hierarchy
- When to use method overriding vs. method overloading
What is inheritance in Java?
Inheritance is a programming construct that software developers use to establish is-a relationships between categories. Inheritance enables us to derive more specific categories from more generic ones. The more specific category is a kind of the more generic category. For example, a checking account is a kind of account in which you can make deposits and withdrawals. Similarly, a truck is a kind of vehicle used for hauling large items.