+ 1

Anybody fix this code ?

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } class Square extends Shape{ void area (){ width= x; System.out.println(width*width); } } class Circle extends Shape{ void area(){ width = y; System.out.println(Math.PI* width * width ); } } //your code goes here 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(); } }

29th Sep 2021, 3:28 PM
Amala Yakin
2 Respostas
+ 2
Please feel free to tag me if you got any doubts about how I fixed your code (I used constructors BTW) =) https://code.sololearn.com/c2f9npXhtxud/?ref=app
29th Sep 2021, 3:48 PM
Rishi
Rishi - avatar
0
abstract class Shape { int width; double widt; abstract void area(); } //введите код сюда class Square extends Shape{ Square(int width){ width *= width; this.width = width; } void area(){ System.out.println(width); } } class Circle extends Shape{ Circle(double width){ width *= width * Math.PI; this.widt = width; } void area(){ System.out.println(widt); } }
29th Sep 2021, 10:51 PM
Kazi
Kazi - avatar