Getter and setter

Most commonly used concept in real projects or MVC project.

Example

class student{
     int id;
	 String name;
	 
	 public int getId(){
	     return id;
		 }
		 
	 public void setId(int id){
	    this.id=id;
		}
	
	 public String getName(){
	     return name;
		 }
		 
	 public void setName(String name){
	    this.name=name;
		}
}
	  
          

class test {
    public static void main(String args[]){
	 
	    student s=new student();
		
	    s.setId(123);
		System.out.println(s.getName());	
		
		s.setName("Bhanu");
		System.out.println(s.getName());
		
		}
		
}
	  
          

Notes:

get and set method to access value from object
Object directly not access data member

Address

Plot number-56/1
Near Gurudwara
LandMark :
Opposite A.N.D college
Govindpuri Metro station
New Delhi
Mobile number:
8826034620