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
any example of games that is created by java ?

What are the different points where weaving can be applied? Ans) There are three points ? Compile Time ? Classload Time ? Runtime


Task I have an Android mobile app project that I''m trying to get profiles to transfer by connecting to a server at 23.23.175.213 port 1337. I have to send a json string to the se

What is final class? A final class can't be extended ie., final class might not be subclassed. A final method can't be overridden when its class is inherited. You can't alter v

What are Trojan Horses? Trojan Horses are unlike viruses usually they are stand-alone programs. The look such as what they are not. They appear to be something harmless and int

What is linear search? It is the simplest form of search. It searches for the element sequentially starting from first element. This search has a drawback if element is located

Spring configuration file is an XML file. This file having the classes information and defines how these classes are configured and introduced to each other.

You are part of a team creating a system to keep track of computer science books that a publisher is producing. Create a UML class diagram for a "computer science book". You must h

how can i implement Mid-Square hashing?