Java Public Attributes

Java Public Attributes


Public attributes In Java
 
Public is an access modifier hence we can use it to make a class, attribute, method, etc Public.
A Public keyword is used when we want to make something only accessible data of one package into another package, it may be data class members or methods.
In other words, if the class is public but the class members defined inside the boundary of that class is not public then we can not access them.
 
Now we will see an example -
 
Example - Now we will take reference from the previous example  
 
 
Here we can see unlike the previous example the class is public but the class data is made public.
 
 
Output - 
 
 
Here we can see we are unable to access data from outside the boundary of the package even when the class is public.