Encapsulation

From TRCCompSci - AQA Computer Science
Revision as of 21:27, 16 December 2016 by Admin (talk | contribs)
Jump to: navigation, search

Encapsulation is concept of packaging together all of the data items and methods from an object. The data values within an object or class would separated from the methods. This is done with key words such as "public", "private" and "protected". Data items will normally be private to protect them, and the class or object will have public methods which can access or assign a value to the private data item.This prevents a direct link between the two.

Public

The "public" modifier allows data to be viewed and manipulated by any part of the program.

Private

The "private" modifier means that only the class in which data is declared can it be viewed.

Protected

The "protected" modifier means that only the class in which data is declared and its subclasses can see the data.