+ 1

What should I put in my constructor to make this work?

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape{ public void area(int width){ System.out.print(width*width); } } 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(); } }

23rd Jul 2021, 9:19 AM
Paul Berger
Paul Berger - avatar
1 Resposta
+ 2
You didn't create any constructor: public class Square extends Shape { public Square(int w){ this.width = w; } @Override public void area() { System.out.println(width * width); } }
23rd Jul 2021, 9:52 AM
Baribor Saturday
Baribor Saturday - avatar