Programming Tutorials

Java program to calculate volume of a Box

By: Paawan Chaudhary in Java Tutorials on 2012-09-19  

This is a Java program to accomplish following task.

  1. Create a user-defined package box which has a class definition. For box having data member and disp()method . (Assume suitable data )
  2. Source file imports above package and calculates the volume of box .
import java.lang.*;
import java.io.*;
Pacakage BoxPackage
{
	public class Box
	{
		int length, breadth, height;
		Box(int I,int b,int h)
		{
			length=l;
			breadth=b;
			height=h;
		}
		public void display()
		{
			int volume=length*breadth*height;
			System.out.println("Volume of Box is"+volume);
		}
	}
}
import.BoxPackage.*;
class Boxdemo
{
	public static void main(string args[])
	{
		Box b=new Box(10,20,30);
		b.display();
	}
}





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)