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
What is the difference among ForwardAction and IncludeAction? Ans) The difference is that you require to use the IncludeAction only if the action is going to be contained by ano

Is it right that garbage collection guarantee that a program will not run out of memory?

Explain the Member Access Separator ? class Car { String licensePlate; // e.g. "New York 543 A23" double speed; // in kilometers per hour double maxSpeed; // in

What are Checked and UnChecked Exception? A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making a

Corporate Web Support: Worked for CGI as Software Engineer in a team called CWS (Corporate Web Support). We support more than 400 applications for BELL Corporate. Here tas


Project Description: Overview I am seeking an Oracle ADF mobile app and web service to be created that takes a list of contacts stored on an Android mobile phone or tablet an


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

Prepare a Java program to read .GPX files Project Description: Prepare a Java program (GPX_Tracks_to_Text.Java) for Windows to: - Read every .GPX file in a provide drive a