Data Hiding

Data Hiding

 Data Hiding

Outside people can't access our internal data directly are our internal data should not go out directly this oops feature is nothing but data hiding. after validation or authentication outside person can access our internal data.

In other words-:

In Object Oriented Programming, the term data hiding refers to hiding internal object details such as data members from outside users. In simple words, data hiding is used to hide or secure the data of a particular from the outside access of the class.

example 1-: After providing the proper username and password we can able to access our Gmail inbox information.

example 2-: even though we are a valid customer of the bank we can able to access our account information and we can't access others' account information.


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

eg-:

public class Account{
    private double balance;
    public static double getBalance(){
            //perform  validation
              return balance;
   }
}

Advantages of data hiding -: the main advantage of data hiding is security.
eg-:
The advantage for programmers is that there is no way for a programmer to accidentally link to incorrect data. Data hiding ensures that, if a programmer does make this link, the program will simply return an error so the programmer can quickly correct the mistake. This also ensures that all of the objects are truly isolated units, which is the main concept of object-oriented coding. Volatile data are typically hidden because, if such data were made public, it could damage the object and destroy the entire program.

Note -: it is highly recommended to declare the data member (variable ) as private.