Categories
Uncategorized

Package in Java

package tr2;

public class pack {

private int callme;

public String name;

private void pdis()
{
callme=5;
System.out.println(“This is private method calling callme ” + callme);
}
public void pudis()
{
System.out.println(“This is public method”);
}   

    public static void main(String args[])
{
pack p2=new pack();
p2.pdis();

}

}

package package1;
import tr2.pack;
public class mainpack extends pack{

     public static void main(String[] args) {

mainpack s1=new mainpack();
s1.pudis();
//s1.pdis(); //cannot call private methods
}
}

Note:TO execute this program we need to make a package in IDE and use this program or if you want to do with command then put the program in 2 different folder with the respective package and execute it.