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

How will you calculate the depth of a binary tree if the tree contains 15 nodes?

1079


What is the use of join method?

1026


Are private methods final?

901


What is the use of put method?

950


What is the static block?

1067


What is the difference between the paint() and repaint() methods in java programming?

1187


What is int short for?

1043


What is the core java?

948


Whats the difference between notify() and notifyall()?

1039


What do you mean by stream pipelining in java 8?

1225


Why webdriver is an interface?

1052


What is function declaration?

960


Can we use a switch statement with strings?

1051


What is volatile keyword in java

1120


What is volatile data type?

1006