public access modifier
RULE: public is key word and it is an access modifier, we can apply this modifier for classes,methods and variables .
we can access from the program and out side of the program of out side packages.
Recommended for classes and method but not variables.
Demo:
package demo.publ;
public class DemoPublic
{
public methodDemo
{
System.out.println("public method in demo.publi.Demopublic");
}
}
package demo.pub2;
import demo.publi.DemoPublic;
public class UsePublic
{
public static void main(String at[])
{
Demopublic p=new Demopublic();
p.methodDemo();
}
}