Aim:

          To perform the package concept in the java programming language

Algorithm:

Step1:   create a new text document.

Step2:   Type the java program for implementing  the package concept.

Step3:   Create a pack named “Mypack”  using  package  keyword and create a super
        class named “Balance”.

Step4:    Assign the variable name as “name” and “bal”, and initialize “name =n”,
“bal=b”.

Step5:    “if” condition is used to check the condition for balance is greater then 0.

Step6:   The “import” keyword is used to import the package program.

Step7:   Create a main class named “TestBalance”, and create an object named “ob”.

Step8:   Print  the name and balance.

Step9:   Save the super class program and sub class program using “.java” command.

Step10:  Using “javac” command for compiling and using “java” command  for run the
program.


PROGRAM


package Mypack;       
public class Balance
{
public String name;
public 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);
}
}
import Mypack.Balance;
class TestBalance
{
public static void main(String args[])
{
Balance ob=new Balance("Ramu",99.88);
ob.show();
}
}


OUTPUT:


                                       Ramu $ 99.88

BY
       REGU RAM SV.

Post a Comment

أحدث أقدم