Encaspsulation

 

     Data Protect (Data Hiding)

  Encapsulation is a concept used to protect data. Then, we use encapsulation to protect our        data and store them safely.

  Why do we use a capsule to store medicine in it?
   Because we need to protect medicine, we use a capsule.

  In this scenario, medicine is the code, capsule is the concept Encapsulation.

  What is data protect?
  Accessing only in present class (The class that the data is located)

   When data protecting other classes can't access the data whose outside the related class.


  Refer to this code sample give below, 

   class Human {
   private int id;
   private string name ;
   private int age;
   }
   class RunProgramme {
  public static void main (String[]args) {
   Human h = new Human ();
   h.id = 3567231567;
   h.name = "Kamal"
   h.age = "34"
   }
  }

  Here, the data is properly protected & stored safely, applying keywords correctly by encapsulation.

-(13th Article)        
                                                                                                    


Thank You!
                                                                                                           


                                                                                                            
                     
                                                                                                       -Article about Java by Hirun Yapa

Comments

Popular posts from this blog

Interfaces

Super Keyword

Abstract Classes