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.                                                                             
import java.util.*;

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

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

Example of abstract class