-> what is inheritance in java
This page describe when you want to overwrite a particular class if it differs from the standard method.
Example:
To inherit the characteristics of a class we saw on the inheritance page that, we could use the keyword extends. Subsequently we make a super-class in which we could write a method which hold for all classes that uses that same method. So, if I’ve a dog and a cat that are both black I am able to categorise my 2 pets in one group: black pets. Because they have something in common, therefore my method which prints the color is for both the same.
In the case that I have 9 pets, which are all black, this is a good way to deal with this problem, because I only have to add once: that my pets are black. Plus, every order characteristic they got in common I could add to my blackPets class. So I want to add that all my black pets have green eyes as well.
Now the problem. I’ve 9 pets all black, but one cat has a black fur with some white stripes. I want that all the characteristics for my black cats hold true, therefore I only want to change their color to black and white.
Problem: want to change one characteristic of one of my pets.
To solve this problem: I can simply write in the class of the black and white cat;
Output:
Easy ;p