Question
CODE IN JAVA Write an abstract class called Animal with encapsulated attributes name (String) and id (integer). The method String toString() inside the Animal class
CODE IN JAVA
Write an abstract class called Animal with encapsulated attributes name (String) and id (integer). The method String toString() inside the Animal class is abstract. Provide getters and setters for the attributes. Write a concrete class called Tiger that extends from Animal class and toString() method returns Tiger + name. Write a class called AnimalHandler with static methods static void write(Animal animal) and static Animal read(). The write method, takes an object of type Animal and writes the object in a binary file in called animals.ser in write mode (meaning this file will always save one Animal at a time). The read method reads back the Animal object from the file and returns it.
Create a main method where you test the AnimalHandler class by passing an object of type Tiger and an object of an anonymous class that extends the Animal class and toString() method returns I am an animal. Call both write and read methods from AnimalHandler.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started