Variable_Encapsulation1
Objective :
  • private scope is limited with the class members
  • public variable is visible to all clients.
Runtime view

Script used :

public class ClassTemplate1 {

/**
*
*/
public String str1; private String str2;
public ClassTemplate1() {
// TODO Auto-generated constructor stub
str2="encapsulated strictly Private scope";
System.out.println(str2);
}

/**
* @param args
*/

public static void main(String[] args) {
// TODO Auto-generated method stub
ClassTemplate1 cls1 = new ClassTemplate1();
System.out.println("Hello World");
cls1.str1 = "This is a public string";
System.out.println(cls1.str1);
}

}