java Encapsulation

encapsulation is a mechanism for wrapping up data and methods to the single unit called class. Doing so the data is not accessible to the outside world and is only accessible to the outside world and is only accessible to the methods that are wrapped in a class. These methods provide the interface between the objects data from direct access is called data hiding.

Encapsulation makes it possible for object to be treated like ‘black boxes’, each performing a specific task without giving any information regarding internal implementation.

e.g:     

class box

{

private int length;

private int breadth;

area()

{

return(length*breadth);

}

Leave a Reply

Your email address will not be published. Required fields are marked *