Create a user-defined package box which has a class definition. For box having data member and disp( ) method

Write a JAVA program to accomplish the 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 the 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();
	}
}

 

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is senior ICT professional who talks about #it, #cloud, #servers, #software, and #innovation. Rabins is also the first initiator of Digital Nepal. Facebook: rabinsxp Instagram: rabinsxp

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *