Saturday 1 December 2012

Abstraction Vs Encapsulation

Leave a Comment
Encapsulation: Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.


 String myName;
 private String setMyName(String name)
 {
           if(name.length()<7)
            {
                 this.myName="Not Assign"
             }

           else
            {
              this.myName=name;
            }
 }


Abstraction is the process of abstraction in Java is used to hide certain details and only show the essential features of the object

class A
{
  public void display()
 { 
    System.out.println("Hi Access Every Where");
 }

 private void displayMe()
 {
   System.out.println("Hi Access Only in class A");
 } 

}

0 comments:

Post a Comment