Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is encapsulation? Elaborate with example?

Answer Posted / devarathnam.c,kotagudibanda,ka

Hi,
Encapsulation: The wrapping up of a data and methods into a
single unit is called Encapsulation. You can achieve
Encapsulation by using private data and public methods look
at the following example for better understanding.
Eg:
public class EcapTest{
public static void main(String args[]){
private int a=22;
private String s="DEVARATHNAM";
private float f=33.24f;

public void displayData(){
// some code
}
public void getData(){
// some code
}
}//main
{//class.

Observe the above program we are combining both data and
methods into a single unit(EcapTest). I hope i met your
needs.

Is This Answer Correct ?    23 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is use of map in java?

1005


What is passed by reference and pass by value ?

1028


How are variables stored in memory?

1060


What are java threads?

1124


What are the different types of sorting in java?

974


Why main method is called first in java?

1004


How do you create immutable object in java?

1038


Why synchronization is important?

1018


Which sorting is used in arrays sort in java?

1077


Can you explain the cs option of java interpreter?

942


Explain the difference between serializable and externalizable in java?

1051


What are the different tags provided in jstl?

953


What is vector?

1053


What is the order of arraylist in java?

1123


Why is core java important?

1031