Encapsulation refers to the hiding of items of data and methods within an object. This is achieved by specifying them as private in the definition of the class. Being able to encapsulate members of a class in this way is important for the security and integrity of class objects. You may have a class with data members that can take on only particular values. By hiding the data members and forcing the use of a method to set or change the values, you can ensure that only legal values are set.
Another major advantage of encapsulation is the ability to hide the implementation of a class. By allowing only limited access to the members of a class, you have the freedom to change the internals of the class without necessitating changes to programs that use the class. Click here to download the code that demonstrate encapsulation.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment