In my last post we were looking at classes..
but today we will get into an concept of an object Inheritance
Objects
An object is an instance of a class. Remember we had a blueprint and an actual house using that blueprint we build a house (object) funny thing is you can build as many houses as you want with the same blueprint this is how object work
Inheritance
Now what if you wanted to build a house but of different kinds for example stone built house or a brick house
a brick house can have the same thing that the stone house has for example the floors, tiles and even color but it has extra things on top like Bricks instead of Stone
But if you already have a blue print for a stone house we don't need to create another separate print for creating a brick house because there's so much information (fields) and even functions (methods) that both the brick and stone house have of course here is where Inheritance Comes in.
In Java a class can inherit everything from another class here there is a child class and a parent class.
Without inheritance we'll be rewriting the same blueprints all the time.
With inheritance we can stand on what already exists modify it to work a little differently like add a few rooms in the brick house from the stone house. Even overwrite a method by changing what it does instead of rebuilding from the ground up again.
The more I learn Java the more i did deeper into Object oriented programming and how things can be connected
Inheritance is a means of connection of classes. Classes either build on top of one another or they relate to each other. The child knows what the parent knows like a hand me down of methods an fields.
This is what I think in Java in general everything is connected to something else there is no such thing as separate concepts something can be connected to something else
Top comments (0)