Import java.util.*;
Abstract class geometry{
public abstract double Getarea ();
}
Class pillar{
Geometry Bottom;
Double height;
Pillar (Geometry bottom, double height) {
This.bottom=bottom;
This.height=height;
}
Public double Getvolume () {
Return Bottom.getarea () *height;
}
}
Class Circle extends geometry{
Double R;
Circle (Double R) {
This.r=r;
}
Public double Getarea () {
return (3.14*R*R);
}
}
Class Rectangle extends geometry{
Double A, B;
Rectangle (double a,double b) {
This.a=a;
This.b=b;
}
Public double Getarea () {
return (A*B);
}
}
public class Main {
public static void Main (String args[]) {
Pillar Pillar;
Geometry Bottom;
Bottom =new Rectangle (12,22);
Pillar=new pillar (bottom,58);
System.out.println ("area of the rectangle" +pillar.getvolume ());
Bottom=new Circle (10);
Pillar=new pillar (bottom,58);
System.out.println ("Volume of Cylinder" +pillar.getvolume ());
}
}
Java for abstract programming examples