Volume of Box coderinme

Volume of Box coderinme

Write a program to make use of a parameterized method inside a class. Take the following case: Create a class Box and define a method in this class which will return the volume of the box. Initialize two objects for your class and print out the volumes respectively.
If box is of different sides then it forms a cuboid:
Volume of a cuboid = length × breadth × height
If box is of same sides then it forms a cube:
Volume of a cube = side × side × side
Program:

class Box 
{
private double x,y,z;
public Box(double a,double b,double c) 
{
x=a;
y=b;
z=c;
}
public double getVolume() 
{
return(x*y*z);
}
}
public class Q25 
{
public static void main(String[] args) 
{
Box b1=new Box(3,4.4,5.6);
Box b2=new Box(2,5.2,2.1);
System.out.println("The volume of first box="+b1.getVolume());
System.out.println("The volume of second box="+b2.getVolume());
}
}

For more programs on Java, visit our Java Archives

Volume of Box coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.