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

Program to explain Importing Package example in Java

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

//  Program to explain Importing Package

package MyPack;

public class  Balance 
{
String name;
double bal;

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

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

// Second File as( BalanceImport.java in current folder) :

import  MyPack.*;

class  BalanceImport 
{
public static void main(String args[ ]) 
{
 Balance ob = new Balance("Nils", 234.56);
 ob.show(); 
}
}


Output:

Nils:  Rs. 234.56


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.