Java- Data Hiding/ Chapter -1 / OOP's Concept

Data Hiding:-

Outside person cannot access our internal data directly.
                                    or
Our internal data shouldn't go out directly this OOP's feature is called as "Data Hiding".

After validation or identification outside person can access our internal data.  

example 1: -After entering valid username and password we can able to access our Gmail account information.

example 2: -Even though we are the valid customer of the bank, we can able to access our account information and we can't access other's account information.

                  HOW ACHIEVE DATA HIDING


By declaring data member (variable) as private we can achieve data hiding. 

example:-

public class SBIAccount
{
            private double balance;
          /*some more code here*/
            public double getBalance( )
          {
                   // Validation
                    return balance;
          }
 }

The main advantage of data hiding is "Security".
It is highly recommended to declare data member (variable) as private.

No comments:

Post a Comment

Be the first to comment!

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.

Regards,
JavaByChetan
Back To Home

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com