Inheritance in Java.
You can build on what you already know.
Inheritance in Java is a concept where a new class (derived class) can take on the properties and behaviors of an existing class (base class). The child class inherits these characteristics from the base class, allowing it to use and extend the base class’s functionality without rewriting code of the base class.
Imagine this, in the old days mobile phones were only useful for calling and texting, but now newer types of mobile phones has extended the functionality to not just calling and texting but browsing the internet, making online transactions etc. You can say that these newer types of phones inherited the functionality of the old model and added new features.
What is direct substitution? Direct substitution is when a derived type (class) has the same methods as the base class. It is often referred to as substitution principle. We often refer to the relationship between this type of base class and its derived class as a “is-a” relationship e.g. “a circle is a shape”. A test for inheritance is to have a “is-a” relationship test between the classes and have it makes sense.
There are times when you must add a new interface element to the base class, thus extending the interface. The derived class can still be substituted for the base class, but it is not a perfect substitution because the base class can’t access the derived class’s newly added methods, this relationship is described as an “islike-a” relationship.
Reminder: An interface is an implementation of an object where the class name and members are visible to the user or hidden if necessary to provide a certain level of abstraction to the implementation of the members. Check out my publication on objects here in case you missed it, https://godwinedeh.substack.com/p/objects-in-java.
You can also change the behavior of the derived class’s method making it do something different from the original method of the same name in the base class, this is called method override.
That’s it for today, if you’ve learned something today do well to subscribe, and thank you for your time.


