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
using polymorphism to write a program to display digital clock

any example of games that is created by java ?

YES. JSP technology is extensible by the development of custom actions, or tags, which are encapsulated in tag libraries. #question..

You are required to design & implement online food delivery system using Java RMI technology. This involves writing both the server and the client program(s). Client programs can u

Problem statement Part 1 Write an aspect that counts different kinds of method calls in a Java program. Your aspect should meet the following requirements:  The aspect should ma

Conway's Game of Life is a "cellular automaton" that is played on a 2D grid (array) of cells. At the start of the game, an initial configuration is set up in which a number of cell

what is the use of design pattern in java ?

Write a program in Javascript that will read in an XML file. This file will contain details of devices maintained by the IT department of an organisation including an ID number, de

Can a class implementing a Remote interface have non remote processes? Ans) Yes. Those processes behave as normal java process operating within the JVM.

The Local Systems IP Address and Port Number and the Remote System's IPAddress and Port Number.