In Java, the public keyword is an access modifier for class, method and variable:
To summary, public is the access modifier that has least restriction on the object it modifies.
The following code example shows a public class which has a public method eat() and a public variable name:
public class Person {
public String name;
public void eat() {
}
}
Related keyword: protected and private. See all keywords in Java.
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.