Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

How can a network design tool help in network design?

Answered: 1 week ago