Question: Java Consider the following classes and interface declarations interface Sleep public String sleep); class Human implements sleep public String sleep() return Humans sleep 8 hours;

Java Consider the following classes and interface declarations interface Sleep public StringJava

Consider the following classes and interface declarations interface Sleep public String sleep); class Human implements sleep public String sleep() return "Humans sleep 8 hours"; class Dog implements sleep f public String sleep) return "Dogs sleep 14 hours"; class Cat implements Sleep public String sleep) f 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 Cats sleep 16 hours Dogs sleep 14 hours Humans sleep 8 hours Cat c new Cat ; Human h new Human(); Sleep[] s (c, d, h printsleep (s)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!