Recent

Powered by Blogger.

Services

Navigation-Menus (Do Not Edit Here!)

Popular Posts

Wednesday, October 19, 2016

Tag:

Encapsulation in Java with example

I have already discussed a brief about encapsulation while discussing OOPs concepts. I have also covered polymorphism and inheritance in separate articles. In this post we will discuss encapsulation in java with examples. What is encapsulation? The whole idea behind encapsulation is to hide the implementation details from users. If a data member is private it means it can only be accessed within the same class. No outside class can access private data member (variable) of other class. However if we setup public getter and setter methods to update (for e.g. void setSSN(int ssn))and read (for e.g. int getSSN()) the private data fields then the outside class can access those private data fields via public methods. This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes. That’s why encapsulation is known as data hiding. Lets see an example to understand this concept better.

About Unknown

Hi, My Name is Hafeez. I am a webdesigner, blogspot developer and UI designer. I am a certified Themeforest top contributor and popular at JavaScript engineers. We have a team of professinal programmers, developers work together and make unique blogger templates.

0 comments:

Post a Comment

Ads Inside Post

 

Like on Facebook