Private keyword in Java

Private keyword is an access modifier in java. Private keyword in java is a brick wall between you and the client programmer. it means no one can access like classes attributes and constructions

Example of private keyword in java


public class  Privatekeyword{
  private String fname = "John";
  private String lname = "Doe";
  private String email = "[email protected]";
  private int age = 24;

  public static void main(String[] args) {
    Main myObj = new Privatekeyword();
    System.out.println("Name: " + myObj.fname + " " + myObj.lname);
    System.out.println("Email: " + myObj.email);
    System.out.println("Age: " + myObj.age);
  }
}



Leave a Comment