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.




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
Application or website to upload DICOM files from CD to Drop box etc Project Description: I need a website code or application to make patients put a cd or DVD to their disk

Padovan String

Explain the library java.lang.Math ? The Java class library is huge. We will not cover it all presently. In fact, the remaining eight classes will focus mostly on the class lib

Java Remote Method Invocation (RMI): It gives a way for a Java program on one machine to interact with objects residing in different JVMs. The important blocks of the RMI arc

Does RMI-IIOP support dynamic downloading of classes? Ans) No, RMI-IIOP doesn't support dynamic downloading of the classes as it is complete with CORBA in DII (Dynamic Interface

RMI Object services: In addition to its remote object architecture, RMI gives some basic object services, which may be needed in a distributed application. 1.  Object namin

What is Runnable JAR archives You can run a program stored within the JAR archive that has a main() method like this: $ java -cp eharold.jar MainClassName You must use the f

Why do we need wrapper classes? It is sometimes simpler to deal with primitives as objects. Moreover most of the collection classes keep objects and not primitive data types. A

Write a program called Grid. The program starts by prompting (asking) the user for the name of an input text file. This file is guaranteed to be correct and has the following fo

Both synchronous and asynchronous are given by JMS.