(this is question1) public abstract class Shape { public Shape() { } public abstract double area() ; public String who()
Posted: Sun May 15, 2022 11:59 am
(this is question1)
public abstract class Shape {
public Shape() { }
public abstract double area() ;
public String who() { return "Shape" ; }
}
public class Circle extends Shape {
private int radius ;
public Circle( int r )
{
radius = r ;
}
@Override
public double area()
{
return Math.PI * radius * radius
;
}
}
public class Square extends Shape {
private int _sideLength ;
public Square( int sideLength )
{
/* TODO question 45 */
}
@Override
public double area()
{
return _sideLength *
_sideLength ;
}
}
What is the output of the following code (approximate answer ok
if needed)? Assume your constructor from question 1 above has
been implemented and the following code is contained within a
driver class.
public static void main(String[] args)
{
report(new Circle(4));
report(new Square(5));
}
public static void report( Shape s ) {
System.out.println(s.who());
System.out.println(s.area());
}
public abstract class Shape {
public Shape() { }
public abstract double area() ;
public String who() { return "Shape" ; }
}
public class Circle extends Shape {
private int radius ;
public Circle( int r )
{
radius = r ;
}
@Override
public double area()
{
return Math.PI * radius * radius
;
}
}
public class Square extends Shape {
private int _sideLength ;
public Square( int sideLength )
{
/* TODO question 45 */
}
@Override
public double area()
{
return _sideLength *
_sideLength ;
}
}
What is the output of the following code (approximate answer ok
if needed)? Assume your constructor from question 1 above has
been implemented and the following code is contained within a
driver class.
public static void main(String[] args)
{
report(new Circle(4));
report(new Square(5));
}
public static void report( Shape s ) {
System.out.println(s.who());
System.out.println(s.area());
}