Data Hiding

  1. The data should not go out directly i.e outside person is not allowed to access the data,this is nothing but “Data Hiding”.
  2. The main advantage of data hiding is we can achieve security.By using private modifier we can achieve data hiding.

Example:

public class Account{
   private double amount;
   private long accountNo;
}

Note:It is highly recommended to declare data members with private modifier.

Abstraction

  1. Hiding the internal implementation is nothing but abstraction.
  2. The main advantages of abstraction are.
    • we can achieve security as we are not highlighting internal implementation.
    • Enhancement will become easy.Because with out effecting outside person we can change our internal implementation.
  3. By using Abstract classes and interfaces,We can achieve abstraction.