0

What am I missing on this code?

I am resolving a code coach and here is my code: import java.util.Scanner; import java.lang.Math.*; abstract class Shape { int width; abstract void area(); } //your code goes here class Square implements Shape { public Square (int x, int y) { int area() { width = x * y; System.out.println(width); } } } class Circle implements Shape { public Circle (double x, double y) { double area() { double round; round = Math.PI * x * y; System.out.println(round); } } } 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(); } } I am very close, but somehow, I am not quite done. Can someone explain to me what am I missing?

21st Feb 2023, 3:30 AM
Gradi Maxime Kasita Mbatika
2 Antworten
+ 4
You have many mistakes :- You cannot define method inside constructor. Shape is not an interface so you cannot implement ot area() has return type void in abstract class so you cannot override it with int and double return type.
21st Feb 2023, 3:49 AM
A͢J
A͢J - avatar
0
Thank you AJ! 😁👍
21st Feb 2023, 3:55 AM
Gradi Maxime Kasita Mbatika