0

How can fix it

import java.util.Scanner; abstract class Shape { int width=0; abstract void area(); } class Square extends Shape { public void area(int width){ System.out.println(width*width); } } class Circle extends Shape { public void area(int width){ 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(); } }

8th Mar 2023, 5:50 PM
Lazhar Dbara
2 Réponses
+ 4
You don't have any constructor to pass x and y u have to pass x and y to area Like a.area(x) And b.area(y) import java.util.Scanner; abstract class Shape { int width=0; abstract void area(int width); } class Square extends Shape { public void area(int width){ System.out.println(width*width); } } class Circle extends Shape { public void area(int width){ 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(); Circle b = new Circle(); a.area(x); b.area(y); } }
8th Mar 2023, 6:23 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Thnk u brother
8th Mar 2023, 6:34 PM
Lazhar Dbara