Beej's Bit Bucket
a day ago
- Inheritance allows a class to inherit attributes and methods from a parent class, forming a class hierarchy.
- The superclass (base class) provides common functionality, and subclasses extend it, improving code reuse and maintainability.
- Polymorphism enables subclasses to override methods, and the correct method is called even when using a base class reference.
- Example: Animal superclass with legCount and hasFeathers; Armadillo subclass overrides eat() and adds armorRating.
- In Java, all methods are virtual (can be overridden) unless declared final; in C++, methods must be declared virtual.