Whats in this post?
- Background and Explanation of the code
- Download Code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
An abstract class is a class that is declared abstract—it may or may not include abstract methods.
An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon) When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract. Creating an abstract class called “animals” with default constructor and methods for onomatopoeia for the animal and it’s name.Then, subclass for all the animals species we want to include are created and we implement the already created methods in the abstract class. In the main classwe initialize array from the abstract class animals and cycle through the methods with a for loop.