0
[Solved] Why doesnât this work?
Stuck on the Java tutorial again. Tried for another hour. ââ Update: Solved. https://code.sololearn.com/cmolYYqimeap/?ref=app
4 Answers
+ 4
Albert Tan
Check the abstract method in Abstract class which has void return type not int or double.
And also constructors should have 1 argument which is area.
class Square extends Shape {
Square(int w) {
this.setWidth(w);
}
void area() {
int area = width*width;
System.out.println(area);
}
public void setWidth(int w) {
this.width = w;
}
}
class Circle extends Shape {
Circle(int w) {
this.setWidth(w);
}
void area() {
double area = Math.PI * width * width;
System.out.println(area);
}
public void setWidth(int w) {
this.width = w;
}
}
+ 2
Thanks!!
+ 1
Albert Tan
Change this
width * Math.PI * 2
To
Math.PI * width * width
+ 1
Albert Tan
Area of circle is PI * r * r
Perimeter of circle is 2 * PI * r