Share on Google+Share on Google+

Naresh
Tutorials for Core Java beginners
1 Answer(s)      9 years ago
Posted in : Java Beginners

Can anyone share their example of Encapsulation in java? I'm a core Java beginner.

Ads

View Answers

February 24, 2008 at 7:15 PM


Hi,

Here is the description of Encapsulation in java:

Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.

In other words, encapsulation is the ability of an object to be a container (or capsule) for related properties (ie. data variables) and methods (ie. functions).


public class Box
{
// what are the properties or fields
private int length;
private int width;
private int height;

// what are the actions or methods
public void setLength(int p)
{length = p;}

public void setWidth(int p)
{width = p;}

public void setHeight(int p)
{height = p;}

public int displayVolume()
{System.out.println(length*width*height)...
}

public static void main(String args [ ])
{
Box b1=new Box(3,4,5);
b1.displayvolume();
}


Thanks









Related Tutorials/Questions & Answers:
Good tutorials for beginners in Java
Good tutorials for beginners in Java   Hi, I am beginners in Java... in details about good tutorials for beginners in Java with example? Thanks.   ... the various beginners tutorials related to Java http://www.roseindia.net/java/beginners
Core Java tutorial for beginners
Core Java tutorials for beginners makes its simpler for novices... that programmer will find useful in learning the language. Each Core Java tutorials... understand every aspect of Core Java. Simple explanations to complex tutorials
Advertisements
Java programming for beginners video tutorials
Java programming for beginners video tutorials  Hi, I am trying to find the Java programming for beginners video tutorials. Let's know the url... for Java beginners. All the tutorials contains free examples. Thanks
core java - Java Beginners
core java  i want to get java projects in core java
tutorials - Java Beginners
tutorials  may i get tutorials for imaging or image processing in java  Hi friend, Please explain problem in details what you want with image in java. Thanks
Core Java - Java Beginners
://www.roseindia.net/software-tutorials/detail/10992 visit www.roseindia.net/java...Core Java  Can u give real life and real time examples of abstraction, Encapsulation,Polymarphism....?  I guess you are new to java and new
JAVA(core) - Java Beginners
JAVA(core)  Core Java  In java 'null' is keyword which means object have nothing to store. even not allocated memory
core java - Java Beginners
Core Java interview Help   Core Java interview questions with answers  Hi friend,Read for more information.http://roseindia.net/interviewquestions
core Java - Java Beginners
core Java  how is it possible to create object before calling main() in Java
Core Java - Java Beginners
Core Java  What is Java? I am looking for Core Java Training  Hi friendThe Core Java Technologies and application programming interface... Microsystems. We generally introduce java in two ways, core java and advance java
core java - Java Beginners
core java  hallo sir, in java ,int range is -128 to 127. what about '0' indicate what  Hi, In java byte range is -128 to 127, not of int
core java - Java Beginners
core java  what is object serialization ? with an example   Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/io/SerializingObject.shtml Thanks
core java - Java Beginners
core java  how many keywords are in java? give with category? .../java/language/java-keywords.shtml http://www.roseindia.net/java/master-java/java-keywords.shtml Thanks
core java - Java Beginners
core java  what is thread ? i can't understand it's need?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/thread/ Hope that it will be helpful for you. Thanks
core java - Java Beginners
core java   what is the difference b/w #include and import??  Hi Friend, Do you want the difference b/w '#include in C' and 'import in java'? Thanks
core java - Java Beginners
core java  how to write a simple java program?  Hi friend..."); } } ------------------------------------------- Read for more information. http://www.roseindia.net/java/master-java/index.shtml Thanks
core java - Java Beginners
core java  Can we provide more than 1 try catch block  Hi Friend, Yes you can. For more information, please visit the following link: http://www.roseindia.net/java/exceptions/nested-try.shtml Thanks
core java - Java Beginners
core java  when write java program in editplus.then save&compile the file. 1-text file 2-class file 3-bak file how can get this files plz tell me  Hi Friend, Please clarify your problem. Thanks
core java - Java Beginners
core java  can we write a program for adding two numbers without...-in-java/ it's about calculating two numbers Java Program Code for calculating two numbers http://www.roseindia.net/java/java-conversion/calculating-three
Core java - Java Beginners
Core java  Hello sir/madam, Can you please tell me why multiple inheritance from java is removed.. with any example.. Thank you...://www.roseindia.net/java/master-java/inheritance.shtml Thanks  Hi
core java - Java Beginners
core java  can we define a function in java and answer is yes, then how we define a function in java pls provide code?  Hi Friend, class Numbers{ public int add(int num1,int num2) { return num1+num2
core java - Java Beginners
core java  what are the type of scope variables and use
core java - Java Beginners
core java  hi, what is the difference between method... and Overriding: http://www.roseindia.net/java/javascript-array/modified-java-method-overloading.shtml http://www.roseindia.net/java/javascript-array/modified-java
core java - Java Beginners
core java  Diff b/w Throws and Throw  Hi Friend, Please visit the following link: http://www.roseindia.net/java/exceptions/how-to-throw-exceptions.shtml Thanks  throw is used for throwing exceptions
core java - Java Beginners
core java  write a program to display equilateral traiangle using stars? output will be as follows: * * * * * * * * * * ...://www.roseindia.net/java/ Thanks
core java - Java Beginners
core java  hi.. one probledm from my end how we can perform the TaskSheduling in java ? coming to my project: Its is NMS domain My project is to collect Data from network and store the data in a FileSystem and after
core java - Java Beginners
core java  When we will use marker interface in our application?  Hi friend, Marker Interface : In java language programming...://www.roseindia.net/java/master-java/interface.shtml Thanks
core java - Java Beginners
core java  write a program to add two numbers using bitwise operators?  Hi friend, i am sending running code. public class...://www.roseindia.net/java/ Thnaks. Amardeep
core java - Java Beginners
core java   How to reverse the words in a given [email protected]  Hi friend, import java.io.*; public class...); } } ------------------------------------------------------- Read for more information. http://www.roseindia.net/java/ Thanks
core java - Java Beginners
core java  catch(Exception e) { System.out.println(e); } what is use of this??  Hi Friend, The catch block is used as an exception... the following link: http://www.roseindia.net/java/exceptions/catching-and-handling
core java - Java Beginners
core java  What is the difference between interfaces and classes?  Hi friend, ABSTRACT CLASS Interface... information : http://www.roseindia.net/help/java/a/interface-vs-abstract
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads