Public Java Keyword

public is a keyword defined in the java programming language.

Public Java Keyword

Public Java Keyword

     

public is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the public keyword indicates the following :  

--  It  is used as an access control modifier.
--  It is applicable to a class, a method or a field.  
--   public class, method or a variable are visible to all the classes defined in different package.
--   A public class, method or field can be referenced from outside the class in which it is declared. 

Using a public Keyword within a class

public class ClassName{

public class ClassName1;

}

Declaring public Variable

public class ClassName

{

public class ClassName1;

public int i;

}

Declaring public Method

public class ClassName{
public String Method(){
<statements>
<statements>
...

<statements>
}

}