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
I want Java a Web Technologies expertise Project Description: Good Java knowledge about 4-5 years to develop online enterprise tool. Seeking someone who is interested to w

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

Padovan String

what is methods override?

Create a class HourlyWorker mind: particularHourlyWorker employee. • Declare two data members named wage and hours of double type with private access. • Implement a parameterized c

Explain all Java Primitive Data Types? boolean 1-bit. May take on the values true and false only. true and false are describe constants of the language and are not the s

Model-View-Controller (MVC) is a design pattern put together to help control change. MVC decouples interface from business logic and data. ? Model: The model having the core of

Your first task is to implement the Movie class to store all the relevant information on a single DVD Movie, including its catalog number, title, year of release, rating, rental pe

How to Returning Multiple Values From Methods ? It is not probable to return more than one value from techniques. You cannot, for example, return the licensePlate, speed and m

1. Pre-translated: Before the JSP file has been compiled and translated into the Servlet. 2. Translated: The JSP file has been compiled and translated as a Servlet. 3. I