Requirements:
design a shape interface and its two implementation classes Square and circle, as required:
1 The Shape interface has an abstract method area (), which receives an argument of type double, returning a result of a double type
2 in square and circle, the area () abstraction of the shape interface is realized, and the square and circular areas are calculated, and the square and
circle objects are created in the test class, and the square area with the edge length 2 and the circular area with a radius of 3 are computed.
Package experiment.cpm;
Interface Shape {
double area (double n);
}
public class Square implements Shape {public
double area (double N)
{return
n*n;
}
}
public class Circle implements Shape {public
double area (double N) {return
3.14*n*n;
}
}
public class Test {public
static void Main (string[] args) {
double s1,s2;
Shape circle=new Circle ();
S1=circle.area (3);
Shape Square=new Square ();
S2=square.area (2);
System.out.println ("Square area:" +s2);
System.out.println ("Round area is:" +S1);
}