Home

Tutoring

Subjects

Live Classes

Study Coach

Essay Review

On-Demand Courses

Colleges

Games

Opening subject page...

Loading your content

AP Computer Science a

AP Computer Science a Question of the Day

Practice AP Computer Science a with the production-style question-of-the-day selection for this public URL.

Question 1

Design an interface Cat. The interface must include the functions meow, purr, clean, hungry, isPurring, isClean, isSleeping, and isHungry.

  1. 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(); }
  2. 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(); }
  3. 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(); }
  4. 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.