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

What is wrong with the following code? Correct it. public class Circle{ private

ID: 3877698 • Letter: W

Question

What is wrong with the following code? Correct it.

public class Circle{

      private double radius;

      public Circle(double radius){

               radius = radius;

      }

      public double getArea(){

               return radius* radius*Math.PI;

      }

class B extends Circle{

      private double length;

      B(double radius, double length)

      {

               Circle(radius);

               length = length;

      }

      public double getArea(){

               return getArea()*length;

            }

}

Explanation / Answer

Answer:

The error in the code is in the base class constructor B (parameterized cosntructor) the first statement is you are trying to call super class constructor that is with statement Circle(radius) which was an error. With this statement compiler treats that Cirecle(double) is one of the method of class B. So to avoid this error replace this statement with

super(radius) which callls the base class parameterized constructor.

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