private Keyword: ================ ==> if the data member defined with "private" keyword: 1) we cannot initialize in outside the class 2) we cannot modify in outside the class. Getter and Setter Method: ========================= ==> getter and setter methods can use for initializing the private members of the class. ==> getter and setter methods are by default "public type". setter Method: ============== ==> use to set the data for private data members within the class. Syntax: public void setMethodName(parameter-Name with its type) { this.datamember-name = parameter-name; } getter Method: ============== ==> to get the data of private data members within the class. Syntax: public return-type getMethodName() { return data-member-name; } Note: ===== 1) for one setter method, there is one corresponding getter method which is immediate to the setter method. 2) According to the number of private data members in the class, we can define equal number of setter and getter methods. package AshokIT.OOPs; class Player{ private int pid; private String pname; private String sport; // setting the player id public void setPid(int pid) { this.pid = pid; } public int getPid() { return pid; } // setting player name public void setPname(String pname) { this.pname = pname; } public String getPname() { return pname; } // setting of Sport public void setSport(String sport) { this.sport = sport; } public String getSport() { return sport; } void display() { System.out.println("The Player Details are : "); System.out.println("Name = "+pname); System.out.println("Id = "+pid); System.out.println("Sport name = "+sport); } } public class PrivateDataClass { public static void main(String[] args) { Player p1 = new Player(); p1.setPid(19791); // p1.getPid(); p1.setPname("Rohit"); // p1.getPname(); p1.setSport("Cricket"); // p1.getSport(); p1.display(); System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); Player p2 = new Player(); p2.setPid(79791); p2.setPname("Midhali"); p2.setSport("Cricket"); p2.display(); } } ============================================ package AshokIT.OOPs; class RaviClassData{ private String name; private int n; private String type; private double time; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getN() { return n; } public void setN(int n) { this.n = n; } public String getType() { return type; } public void setType(String type) { this.type = type; } public double getTime() { return time; } public void setTime(double time) { this.time = time; } void printingData() { System.out.println("The Faculty Details :"); System.out.println("Name of the Faculty = "+name); System.out.println("Number of Batches Handling = "+n); System.out.println("Position Type = "+type); System.out.println("Available Timings = "+time); } } public class AshokITFaculty { public static void main(String[] args) { RaviClassData rcd = new RaviClassData(); rcd.setName("Ravi"); rcd.setN(6); rcd.setType("Full Time"); rcd.setTime(8.00); rcd.printingData(); } }