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
how to implement tsp problem using java applet to present in form of visulation

JMS ((java messaging service))is an acronym used for Java Messaging Service. It is Java's answer to formed software using asynchronous messaging. It is one of the official specific

You are asked to write a Java program to calculate the commercial value of the stamps owned by a philatelist. Each philatelist has a name and a collection of stamps. The stamps can

What does it mean that a method or field is "static"? Static variables and methods are instantiated only once per class. In other words they are class variables, not example va

Add WordPress color picker to plug-in text field Project Description: I have a simple plug-in that needs the built-in Word Press color picker added to one of the text input f

how to Using polymorphism to write a program to display digital clock?

What are the Design Goals of Java Massive growth of the Internet and World-Wide Web leads us to a completely new way of looking at development of software which can run on diff

Explain switch statement in java language? Switch statements are shorthands for a certain type of if statement. It is not common to see a stack of if statements all related

Two XML configuration files are uses by The Validator Framework validator-rules.xml and validation.xml. The validator-rules.xml shows the standard validation routines, these are re

Define a function that will take a box type of object as argument and return a box object whose dimension is 10 times more than the object