ContactUs :

Please send your Questions & Answers or Feedback to ""

What is Data hiding ?

Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.


public class EncapTest{


   private String name;

   private String idNum;

   private int age;


   public int getAge(){

      return age;



   public String getName(){

      return name;



   public String getIdNum(){

      return idNum;



   public void setAge( int newAge){

      age = newAge;



   public void setName(String newName){

      name = newName;



   public void setIdNum( String newId){

      idNum = newId;



Related Posts Plugin for WordPress, Blogger...
Flag Counter