0

Java Abstract Class Help

import java.util.Scanner; abstract class Shape { protected int width; abstract void area(); } class Square extends Shape { Square(int width) { this.width = width; } void area() { System.out.println(width * width); } } class Circle extends Shape { Circle(int width) { this.width = width; } void area() { System.out.println((width * width) * Math.PI); } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Square a = new Square(x); Circle b = new Circle(y); a.area(); b.area(); } } This code here is from one of the Java challenges on sololearn, it works for 4/5 of the tests but the one it doesn't work for is hidden and I don't understand why it does not work for that test. The only issue that I can see is that in my IDE it says that the abstract void area() method is never used.

10th Feb 2021, 5:10 PM
James
James - avatar
1 Antwort
+ 1
Maby use Annotations like @Override above the area method but the program looks ok to me
10th Feb 2021, 11:45 PM
D_Stark
D_Stark - avatar