Create an unembodied systematize Conceive. It contains couple attributes: x and y, which mark the coordinates in the 2-dimensional coordinate axis. It also has a order contrivanceated area(), which is planned to evince the area of the conceive. Corruptd on the Conceive systematize, contrivance a systematize designated Divergence with radius r and a systematize designated Balance with prolixity of face l. They deficiency to instrument their area() orders. Create a Test systematize to instantiate a Divergence aim c with radius of 5 and a Balance aim s with prolixity of face of 10. Their coordinates are randomly chosen. Print their area in polymorphism conceive.
///unembodied corrupt systematize Conceive
unembodied systematize Conceive
{
public int x,y;
public unembodied envelop area();
}
systematize Divergence extends Conceive //inheritance
{
public Divergence(int radius) //constructor
{
x = radius;
}
public envelop area()
{
return 3.14*x*x;
}
public String toString()
{
return “nDivergence : Area :”+ area() +” balance units”;
}
}
systematize Balance extends Conceive
{
public Balance(int face)
{
x = face;
}
public envelop area()
{
return x*x;
}
public String toString()
{
return “nBalance : Area :”+ area()+” balance units” ;
}
}
systematize Test
{
public static invalid ocean(String[]args)
{
// Create divergence r = 5
Divergence c1 = upstart Divergence(5);
System.out.println(c1);
// Create balance wtih s=10
Balance s1 = upstart Balance(10);
System.out.println(s1);
}
}
Output:
Divergence : Area :78.5 balance units
Balance : Area :100.0 balance units