Sunday, May 5, 2013

Demonstrate the functionality of packages.


/*Write a java program to create and demonstrate packages.*/
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 + ": $" + bal);
      }
}

   TESTBALANCE.JAVA

   import MyPack.*;

class TestBalance
{
            public static void main(String args[])
            {
                        Balance test=new Balance("J.J.Jaspers",99.88);
                        test.Show();
            }
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More