SyntaxFix
Write A Post
Hire A Developer
Questions
The code generates a compilation error because your instance type is an Animal:
Animal animal=new Animal();
Downcasting is not allowed in Java for several reasons. See here for details.