Create a class Box and display the area of box using a method area(). Initialize all the variables using Constructor and demostrate Constructor Overloading.
2. Create a class Box and display the area of box using a method area(). Initialize all the variables using Constructor and demostrate Constructor Overloading. |
class BoxArea
{
double height;
double width;
double depth;
double area()
{
return (height*width*depth);
}
BoxArea()
{
System.out.println("The New object is created");
}
BoxArea(double h,double w,double d)
{
height=h;
width=w;
depth=d;
}
}
class BoxAreaDemo
{
public static void main(String args[])
{
double height=0,width=0,depth=0;
Scanner in=new Scanner(System.in);
BoxArea b1=new BoxArea();
System.out.println("");
System.out.println("Enter Height :");
height=in.nextDouble();
System.out.println("Enter Width :");
width=in.nextDouble();
System.out.println("Enter Depth :");
depth=in.nextDouble();
BoxArea b2=new BoxArea(height,width,depth);
double ans=b2.area();
System.out.println("Area of Box is :" +ans);
}
}
Comments
Post a Comment