0

SOLVED | pls tell me what is wrong here?

abstract class Shape { public int w; abstract void area(); } class Square extends Shape{ public void area(int w){ System.out.println(w*w); } } class Circle extends Shape{ public void area(int w){ System.out.println(w*w*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(); Circle b = new Circle(); a.area(x); b.area(y);

24th Apr 2022, 4:30 PM
dottxt | off
dottxt | off - avatar
6 ответов
0
Save code and share link. code is cutoff. and Is this about java practice code coach? Then use (Math.PI*w*w), instead of (w*w*Math.PI) for circle area output.
24th Apr 2022, 7:16 PM
Jayakrishna 🇮🇳
+ 2
look good to me
24th Apr 2022, 10:37 PM
Pls Dont Block Me
+ 1
In your class Shape write abstract void area(int w); and in your main method remove the space between the square brackets after String main(String[] args)
24th Apr 2022, 4:46 PM
Stefanoo
Stefanoo - avatar
+ 1
Could you please LINK your code instead of copying it into the description? weren't there any constructors in the given code?
24th Apr 2022, 4:46 PM
Lisa
Lisa - avatar
0
only for abstract class
24th Apr 2022, 5:04 PM
dottxt | off
dottxt | off - avatar
0
import java.util.*; abstract class Shape { public int w; abstract void area(int w); } class Square extends Shape{ public void area(int w){ System.out.println(w*w); } } class Circle extends Shape{ public void area(int w){ System.out.println(w*w*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(); Circle b = new Circle(); a.area(x); b.area(y); } } In your code, you missed the argument for Shape class abstract method.
25th Apr 2022, 7:36 AM
Thineshan Panchalingam
Thineshan Panchalingam - avatar