Question 1
Design an interface Cat. The interface must include the functions meow, purr, clean, hungry, isPurring, isClean, isSleeping, and isHungry.
interface Cat {public String meow();public String purr();public void clean();public void hungry();public boolean isPurring();public boolean isClean();public boolean isSleeping();public boolean isHungry();}class Cat {public String meow();public String purr();public void clean();public void hungry();public boolean isPurring();public boolean isClean();public boolean isSleeping();public boolean isHungry();}interface Cat {public String meow();public String purr();public void clean();public void hungry();public void isPurring();public void isClean();public void isSleeping();public void isHungry();}interface Cat {}
Explanation: The correct answer defines the interface as described. One of the answer choices defines a class with all of the attributes of the interface. Classes and interfaces are different. Interfaces are stubs of methods and classes are typically implementations (this is not always true, look up abstract classes). Another answer choice defines just the stub of the interface. This one would have been correct if the prompt had just asked for the stub, but there were implementation questions involved. Finally, the third answer choice had isPurring(), isClean(), isSleeping(), and isHungry() as void methods. These methods are prefixed with an "is" and "is" typically defines boolean language. Boolean was the correct return method on those.