3 min read

Object Oriented Design (series) - Inheritance

Object Oriented Design (series) - Inheritance
This concept is all about having a base component and adding features over it.

Intro

🧩  It best describes the idea of is a from a programming standpoint using the extends keyword.  

Let's look at an example! We'll take Animal -> Bird. 🕊

public class Animal {
    protected Integer age;
    
    public Animal(Integer age) {
        this.age = age;
    }

    public void eat() {
        System.out.println("Animal eats!");
    }
}
Animal.java

A Bird is an Animal, this is why, it has to have access to the age property and to the eat behaviour of Animal.

❓  Having said that, if we have access to the parent class properties and methods, what is the reason for all of this?

This post is for subscribers only