I have spent many years learning how to drive this car, and I am very good at driving this car. But then one day, I had to move something big from one place to another, and it would not fit inside my little car, so I had to use a truck. I had never driven a truck before: it was very big, much bigger than my little car. But it still had all the parts my car had, only bigger! The engine was a little different: it ran by burning a different kind of stuff than my car's engine burns, but it still went forward and not forwards when I told it to. So I was able to drive the truck just by doing the same things as I do when I use my little red car.
Later on, a friend needed to get their big family to the place where the flying machines land but they didn't want to leave anything just sitting there while they were gone, so they asked if I could drive them there and then drive back to their house. There were too many of them to fit in my small car, so I had to drive a different one: their bus! They have a big bus that fits 18 people at a time! I had never driven a bus before, and this was much bigger than my little red car. But this bus still had four wheels filled with air and a little wheel inside that turned two of them when I turned it. And it still had an engine, and a stick that let me tell it to go forwards or not forwards. It even had the same two white lights on the front so I could see better in the dark, and two red lights on the back to show other people when I am trying to slow down. It was a little different: there were more doors than my car had and many more windows, but the wheels still turned when I turned the small wheel inside. So I was able to drive this bus just by doing the same things as I do when I use my little red car.This is what we call Inheritance.
We're able to make one thing and add a lot of things it can do or things it can remember, and then make a different thing that Inherits from the first thing. When we do this, the second thing is still able to do everything the first thing does, even if it does it a different way (like how the truck burned a different kind of stuff from the little red car). The second thing can even do more stuff than the first thing, like how the bus had more doors, windows, and seats than the little red car.
The truck was still a car and the bus was still a car, and that's why I was able to drive them the same way, but they were also so much more and each of them did a very special job very well.

No comments:
Post a Comment