Public Access Specifier Example Java Program


Access specifiers are keywords in object-oriented languages that set the accessibility of classes, methods, and other members. Access modifiers are a specific part of programming language syntax used to facilitate the encapsulation of components. The public accesses specifier gives access to the member function from outside the class. This part allows the programmer of a class to easily change the data member of the class.


public class class_name{
	//Do something
public method_name(){
	//Do something

Public Access Specifier Example Program

class Main{  
	public int num=789;  
	public void data(){
		System.out.println("She sells sea shells on the sea shore");
class PublicAccessSpecifier{  
	public static void main(String args[]){  
		Main obj=new Main();  

Sample Output

Output is:
She sells sea shells on the sea shore