Difference between revisions of "Encapsulation"
Line 1: | Line 1: | ||
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 be 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. | 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 be 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. | ||
+ | |||
+ | <youtube>https://www.youtube.com/watch?v=oCEaOJgorWo&index=4&list=PLCiOXwirraUAJPwNTW5gxfJK6Ej18fDP9</youtube> | ||
+ | |||
+ | https://www.youtube.com/watch?v=oCEaOJgorWo&index=4&list=PLCiOXwirraUAJPwNTW5gxfJK6Ej18fDP9 | ||
<h2>Public</h2> | <h2>Public</h2> |
Latest revision as of 12:06, 11 June 2018
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 be 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.
https://www.youtube.com/watch?v=oCEaOJgorWo&index=4&list=PLCiOXwirraUAJPwNTW5gxfJK6Ej18fDP9
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.