Encapsulation, JAVA Programming

Defines to keeping all the related members together in an object. Specifying member variables as private may hide the methods and variables. Objects should hide their inner workings from the outside part. Good encapsulation gives code modularity by preventing objects interacting with each other in an unexpected way, which in turn builds future development and refactoring efforts easy.

 

931_Untitled.png

 

Being able to encapsulate members of a class is important for integrity and security. We may protect variables from unacceptable values. The sample code above describes how encapsulation may be used to protect the MyMarks object from having negative values. Any modification to member variable "vmarks" can only be laid out through the setter method setMarks(int mark). This prevents the object "MyMarks" from needing any negative values by throwing an exception.

 

Posted Date: 7/25/2012 1:29:10 AM | Location : United States







Related Discussions:- Encapsulation, Assignment Help, Ask Question on Encapsulation, Get Answer, Expert's Help, Encapsulation Discussions

Write discussion on Encapsulation
Your posts are moderated
Related Questions
There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing tha

Explain the term Event Handler? An event handler is a command that calls a function while an event happens, like as the user clicking a button.

What are the different scopes for Java variables? The scope of a Java variable is explained by the context in which the variable is declared. Therefore a java variable can have

Ask question how to implement a decision tree in java #Minimum 100 words accepted#

If I have a boolean array that contains 30 elements (boolean[] fish), how do I go about isolating every 10 elements to use for something specific? Say there are 30 types of fish s

What are the steps of working of TCP and IP protocols within internet transmission? TCP divide messages in several packets (capsulation) and sent these messages over the internet

Overall Requirements Every phone number is broken up into sections as shown below: Country Code Area Code Prefix Line Number 1 919 882 5000 Write a program to separate out a ph

The fancy new French restaurant La Food is very popular for its authentic cuisine and high prices. This restaurant does not take reservations. To help improve the efficiency of the

In  order  to  provide  portable  and  reliable  EJB  elements,  the  following  restrictions  apply  to  EJB  code implementation: 1. Avoid using static non-final fields. Defin