Difference between revisions of "Encapsulation"
(Created page with "Encapsulation is where information in one part of a program is protected from other parts of the program. This is done with key words such as "public", "private" and "protecte...") |
|||
Line 1: | Line 1: | ||
− | Encapsulation is | + | 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". |
<h2>Public</h2> | <h2>Public</h2> | ||
Line 9: | Line 9: | ||
<h2>Protected</h2> | <h2>Protected</h2> | ||
The "protected" modifier means that only the class in which data is declared and its subclasses can see the data. | The "protected" modifier means that only the class in which data is declared and its subclasses can see the data. | ||
+ | |||
+ | 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. |
Revision as of 21:27, 16 December 2016
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".
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.
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.