Professional Documents
Culture Documents
Practical 20
Practical 20
package MyPack;
public class PackageDemo
{
public void show()
{
System.out.println("show() method in class PackageDemo of Package
MyPack");
}
}
Class PackageImport🡪
===========================================================================
import MyPack.PackageDemo;
class PackageImport
{
public static void main(String[] s)
{
PackageDemo pd=new PackageDemo();
pd.show();
}
}
Output:
XIII. 2. Define a package named myInstitute include class named as department with one
method to display the staff of that department. Develop a program to import this package in
a java application and call the method defined in the package.
Class department in myInstitute Package 🡪
===========================================================================
package myInstitute;
import java.util.Scanner;
Class ImportDept 🡪
===========================================================================
import myInstitute.department;
import java.util.Scanner;
class ImportDept
{
public static void main(String[] s)
{
Scanner in=new Scanner(System.in);
int n,i,j;
for(i=0;i<n;i++)
{
d[i]=new department();
d[i].getstaff();
}
System.out.println("No. Name");
for(j=0;j<n;j++)
{
d[j].putstaff();
}
}
}
Output:
3. Develop a program which consists of the package named let_me_calculate with a class
named calculator and a method named add to add two integer numbers. Import
let_me_calculate package in another program to add two numbers
Class Calculate 🡪
===========================================================================
import let_me_calculate.calculator;
class calculate
{
public static void main(String[] s){
calculator c=new calculator();
c.add(5,5);
}
}
Output: