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);
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.
+ 2
look good to 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)
+ 1
Could you please LINK your code instead of copying it into the description?
weren't there any constructors in the given code?
0
only for abstract class
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.