+ 1
Please what is the error in my code
There are two classes that extends from one base class called shape which has one abstract method called area https://code.sololearn.com/cA11a1A91A11/?ref=app
4 Antworten
0
line 8: 'shape' should be 'Shape'
0
import java.util.Scanner;
abstract class Shape {
int width;
abstract void area();
}
//your code goes here
class Square extends Shape {
Square (int x) {
width = x;
}
public void area() {
System.out.println(width * width);
}
}
class Circle extends Shape {
Circle (int y) {
width = y;
}
public void area() {
System.out.println(Math.PI * width * 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();
}
}
0
why here when i used tge super keyword wich refers to the width in the base class is not working
0
super keyword does not work with Abstract Class , if that was your question