extends & super
Use extends to reuse a base class, and super to call the parent constructor or methods. Keep examples tiny and readable.
What is inheritance?
Inheritance lets a class reuse and extend another class. The child gets the parent's fields and methods, and may add its own. Use it to share common code across similar types.
Using extends
Use the extends keyword to create a subclass. Example idea: class Car extends Vehicle. The subclass is a specific kind of the parent and can reuse its behavior.
All lessons in this course
- extends & super
- Method Overriding
- Polymorphism & Dynamic Binding