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 a class reference?

1016


What is java in simple terms?

948


What does \ mean in regex?

1110


Name few "optional" classes introduced with java 8 ?

1067


What is parsing a string?

1087


Given a singly linked list, determine whether it contains a loop or not without using temporary space?

932


Can you change array size in java?

917


Difference between process and thread?

988


What are the methods of object class ?

997


Give any two differences between C++ and java.

1081


What is java lang string?

942


Does .length start 0 java?

956


Write a java program to print fibonacci series?

908


What is the default value of an object reference declared as an instance variable?

1038


What is definition and declaration?

965