+ 2

I have to found area of shape ...it shows can not find symbol... What's wrong with this code??

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

2nd May 2021, 9:47 AM
Ajay Mistry
Ajay Mistry - avatar
3 Answers
+ 3
It should be this.width = x, not this .width = x Also, its System.out.println()
2nd May 2021, 9:56 AM
Abhishek Tandon
Abhishek Tandon - avatar
+ 1
Use System.out.println for output, not only println
2nd May 2021, 9:56 AM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
0
Thanks 👍
2nd May 2021, 10:06 AM
Ajay Mistry
Ajay Mistry - avatar