Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you have a Car class and Vegetable class; these two kinds of things are

ID: 3681944 • Letter: S

Question

Suppose you have a Car class and Vegetable class; these two kinds of things are completely unrelated but they have the common behaviour of washing both Car and Vegetable objects. However, *how* the process of actually washing a Car object is completely different from washing a Vegetable object. For example, a Car might be washed with a power pump but a Vegetable would be washed in a kitchen sink. Since both kinds of things share a washing process, you might make the wash() method a part of the Washable interface, which you can implement in both the Car and the Vegetable class. What would the stubs (i.e., outline of the Class/Interface *structure only*) look like for these three things (the Washable Interface, the Car Class, and the Vegetable Class)?

Explanation / Answer

public interface Washable{
   public void wash();
}

public class Car implements Washable{
  
   public void wash(){
       // car washing method
   }
}

public class Vegetable implements Washable{
  
   public void wash(){
       // vegetable washing method
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote