Wednesday, June 29, 2016

Tightly Encapsulated Class

Tightly encapsulated Class:

 A class is said to be tightly encapsulated. If and only if each and every variable of class declared as private.

And there is  no need to be worry about whether class contains : corresponding getter and setter methods or not; or whether these methods are declare as public or not.
for example :

example1

  public class Account{
                              private double balance;
                              public double getBalance()
                             {
                                  return balance;
                               }

                             }

example2
 public class A{

                         private int x=0;
                      }


class B extends A
                          {
                           int y=20;
                         }


 in the above  example2  B class is not a tightly encapsulated class. because y variable is not declared as private.


Note : If the parent class is not tightly  encapsulated then  child class will  not be tightly encapsulated.


<<       >>

No comments: