Question: Consider the following classes and interface declarations interface Sleep public String sleepO; class Human implements Sleep i public String sleepO E return Humans sleep 8

Consider the following classes and interface declarations interface Sleep public String sleepO; class Human implements Sleep i public String sleepO E return "Humans sleep 8 hours" ; class Dog implements Sleep I public String sleepO return "Dogs sleep 14 hours" ;} class Cat implements Sleep I public String sleepO return "Cats sleep 16 hours"; Write a static method printsleep() that takes an array of objects of type Human, Dog and Cat as the parameter. The method iterates through the array and for each array element, the method prints "Humans sleep 8 hours" on a single line if the object type is Human; if the object type is Dog, the method prints "Dogs sleep 14 hours" on a single line, and if the object type is Cat, the method prints "Cats sleeps 16 hours" on a single line Write the method in the answer box below assuming that the interface and subclasses have been done for you For example: Test Result Cat c = new Cat(); Dog d - new DogO; Human h new Human Sleep] s - [c, d, h}; printSleep(s); Cats sleep 16 hours Dogs sleep 14 hours Humans sleep 8 hours
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
