You are here: Home / Topics / Program to explain Creating Package in Java

Program to explain Creating Package in Java

Filed under: Java on 2023-09-17 15:36:05

//  Program to explain Creating Package.

package MyPack;

class  Balance 
{
String name;
double bal;

Balance(String n, double b) 
{
 name = n;
 bal = b;
}

void show() 
{
 if(bal<0)
  System.out.print("--> ");
 System.out.println(name + ": Rs. " + bal);
}
}

class  AccountBalance 
{
public static void main(String args[ ]) 
{
 Balance current[ ] = new Balance[3];
 
 current[0] = new Balance("Nils", 123.45);
 current[1] = new Balance("Poojan", 345.12);
 current[2] = new Balance("Darshan", -12.34);
 
 for(int i=0; i<3; i++) 
 {
  current[ i ].show();
 }
}
}


Output:

Nils:  Rs.  123.45
Poojan:  Rs.  345.12
--> Darshan:  Rs.  -12.34


About Author:
M
Mr. Dubey     View Profile
Founder of MCQ Buddy. I just like to help others. This portal helps students in getting study material free. Share your stuff here so that others can get benefitted.