import java.io.*;
class Point
{
protected double x,y;
Point(double a,double b)
{
setpoint(a,b);
getx();
gety();
}
void setpoint(double w,double z)
{
x=w; y=z;
}
void getx()
{
System.out.println("X="+x);
}
void gety()
{
System.out.println("Y="+y);
}
}
class Circle extends Point
{ final double PI=3.14;
protected double rad;
double ar;
Circle(double c,double d,double e)
{
super(c,d);
setrad(e);
getrad();
}
void setrad(double f)
{
rad=f;
}
void getrad()
{
System.out.println("Radious="+rad);
}
void area()
{
ar=PI*rad*rad;
System.out.println("Area of circle is:"+ar);
}
}
class Cylinder extends Circle
{ double hieght;
Cylinder(double k,double l,double m,double n)
{
super(k,l,m);
sethieght(n);
gethieght();
}
void sethieght(double o)
{
hieght=o;
}
void gethieght()
{
System.out.println("Hieght="+hieght);
}
void volume()
{
double p=ar+(2*PI*rad*hieght);
System.out.println("Volume="+p);
}
}
class Mainclass
{
public static void main(String args[])
{
Cylinder c=new Cylinder(10,20,6,4);
System.out.println("Area of circle");
c.area();
System.out.println("Volume of a cylinder");
c.volume();
}
}
OUTPUT
X=10.0
Y=20.0
Radious=6.0
Hieght=4.0
Area of circle
Area:113.03999999999999
Volume of a cylinder
Volume=263.76
No comments:
Post a Comment