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(); } }
2 Antworten
+ 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);
}
}
+ 2
Thnk u brother