Wednesday, November 18, 2015

Program to implement Constructor Overloading.

class Volume
{
double cuboid, sphere;
Volume(double l,double w, double h)
{
cuboid=l*w*h;
System.out.println("Volume of Cuboid = "+cuboid);
}
Volume(double r)
{
sphere=(4/3.0)*3.14*r*r*r;
System.out.println("Volume of Sphere = "+sphere);
}
}
class Multiple_const
{
public static void main(String ar[])
{
Volume cuboid=new Volume(10,20,30);
Volume sphere=new Volume(2.0);
}
}
Output:

No comments:

Post a Comment