Define a SeaLife class with the following private members:
and public members:
Define a subclasses Fish and Crustacean that each extends the SeaLife class.
The Fish class should have the following private members:
and public members:
The Crustacean class should have the following private members:
and public members:
Write a main program with the following declarations:
Fish fish1, fish2;
Crustacean lobster, crab;
Initialize the above references to objects with attributes of your choice. Print out the attributes of each, using toString().
“Stage a few battles” (by invoking wins) between fish1, fish2, lobster and crab, and print the name ofwho wins.
Add a SeaLife array to your main method by declaring: SeaLife[] creatures = new SeaLife[4]. Fill itwith 2 Fish objects and 2 Crustacean objects. Traverse the array with a loop to print out details of eachobject. Use toString() polymorphically.
Place the following statements in your main method in order to report which compile and run ok,which do not compile ok, which compile ok but produce a runtime error.
SeaLife creatureA, creatureB;
creatureA = fish1;
creatureB = lobster;
lobster = fish1;
lobster = crab; // what is lobster’s name now?
boolean b = creatureA.isSwimming();
boolean c = (Fish) creastureA.isSwimming;
boolean d = creatureB.isSwimming();
boolean e = (Fish) creatureB.isSwimming();