Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Tutorials for Core Java beginners
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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
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
core java  i want to get java projects in core java
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 sentence??jagdysbms@yahoo.co.in  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
 

 

 

DMCA.com