encapsulation

1
Why we need encapsulation? Encapsulation is needed 1. To minimize the number of potential dependencies with the highest probability of change propagation 2. In order to make changes in your code without breaking the code of all others who use your code What is encapsulation? Grouping of correlated operations/entities in a single entity that can be named with a single name. It can also be defined as putting together all the variables and methods together in a single unit called class. It is the aggregation of data and behavior. How you will implement encapsulation in java? Encapsulation in java is achieved by declaring fields in a class as private, while providing access to the fields via public typically getter and setter methods. Both data and operations on data (methods) are declared in the same class. Example in notepad Here methods like get name set name, and data like name, no are declared in the same class student. The data name, no are declared private. by this information hiding is provided .

Upload: yamini-kanaparthy

Post on 21-Jul-2016

9 views

Category:

Documents


1 download

DESCRIPTION

basics of encapsulation

TRANSCRIPT

Page 1: encapsulation

  Why we need encapsulation?

Encapsulation is needed1. To minimize the number of potential dependencies with the highest probability of change propagation2. In order to make changes in your code without breaking the code of all others who use your code

What is encapsulation?Grouping of correlated operations/entities in a single entity that can be named with a single name. It can also be defined as putting together all the variables and methods together in a single unit called class. It is the aggregation of data and behavior.   

 How you will implement encapsulation in java? Encapsulation in java is achieved by declaring fields in a class as private, while providing access to the fields via public typically getter and setter methods. Both data and operations on data (methods) are declared in the same class.

Example in notepad Here methods like get name set name, and data like name, no are declared in the same class student. The data name, no are declared private. by this information hiding is provided .