An abstract class is a mixture of an interface & a regular class that has to be inherited. What this means, is you can write abstract methods -- methods that just include the method signature like in interfaces -- but you can also write regular methods that have an implementation.
Since abstract classes cannot be instantiated on their own, to use an abstract class we have to inherit it and then implement the abstract methods.
1. When writing the class header, we have to include the abstract keyword in between visibility and the class keyword.
2. Then we can write any global variables we need.
3. Write the method headers for your abstract methods (just like what you did with interfaces, but with the abstract keyword in between visibility & return type).
4. Any methods that will have actual implementation can be written the same way you have always written a method, and this will not have the abstract keyword.
Polymorphism is normally a biology term to describe how a species can take different forms or stages. For instance, a butterfly did not start as a butterfly, it was originally a caterpillar and morphed into something else.
In Java, polymorphism is when subclasses -- while having their own unique behaviors -- share some of the behaviors of their superclasses. You have already been using this principle, but the most important aspect of it is being able to use the superclasses type to create an instance or define parameters.
1. When creating an instance we can use the superclass type.
2. When defining parameters, we can use the superclasses type also.
This is important because we have to explicitly define our parameters. But now we can just use the superclasses’ type and whenever we make new subclasses, our current methods will still work.