Inheritance
Published Apr 19, 2021Updated Dec 14, 2022
Contribute to Docs
Inheritance is one of the most important principles of object-oriented programming (OOP). It allows for one class (child class) to inherit the fields and methods of another class (parent class).
An inherited class is also called a subclass of its superclass (parent class).
Inheritance is considered one of the four pillars of OOP, along with abstraction, and encapsulation, and polymorphism.
Example
// Parent Classclass Machine {// Machine class member}// Child Classclass Car extends Machine {// Car inherits traits from Machine// Additional Car class members, functions, etc.}
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn more on Codecademy
- Free course
Learn C++
Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.Beginner Friendly11 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly17 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours