Demonstrate the functionality of packages. - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Sunday, October 30, 2011

Demonstrate the functionality of packages.


  1. Demonstrate the functionality of 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();
            }
}

No comments:

Post a Comment