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

Question 13 options: //The first constructor in Apple is not complete. //Write t

ID: 3864913 • Letter: Q

Question

Question 13 options:

//The first constructor in Apple is not complete. //Write the code for that constructor.

public Apple(double pricePerPound, String code, String variety) {

}

Information

public class Fruit {

    private double pricePerPound;

    private String code;

    public Fruit(double pricePerPound, String code) {

        this.pricePerPound = pricePerPound;

        this.code = code;

    }

    public Fruit(String code) {

        this.code = code;

    }

}

public class Apple extends Fruit {   

private String variety;    

public Apple(double pricePerPound, String code, String variety) {   

}    

public Apple(String code) {   

}  

}

This code should be in java format.

Explanation / Answer

public class Fruit{
   private double pricePerPound;
   private String code;
  
   public Fruit(double pricePerPound,String code){
       this.pricePerPound = pricePerPound;
       this.code = code;
   }
   public Fruit(String code){
       this.code = code;
   }
}
public class Apple extends Fruit{
   private String variety;
   public Apple(double pricePerPound,String code,String variety){
       super(pricePerPound,code);
       this.variety=variety;
   }
   public Apple(String code){
       super(code);
   }
}

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