What is encapsulation? Elaborate with example?



What is encapsulation? Elaborate with example?..

Answer / 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

More Core Java Interview Questions

INTERVIEW QUESTION FOR ANDROID

0 Answers  


What is the default access specifier for variables and methods of a class?

0 Answers  


Can a final method be overloaded?

0 Answers  


Why 1 is not a prime number?

0 Answers  


What are the types of statement? explain

1 Answers   SysBiz,






what is mean by method signature?

5 Answers   Satyam,


Which one of the following suits the description of a string better: derived or primitive?

0 Answers  


we have syntax like for(int var : arrayName) this syntax is to find whether a number is in the array or not.but i want to know how to find that number's location.

0 Answers  


What is low level language in computer?

1 Answers  


What is meant by class and object in java?

0 Answers  


How do you sort in java?

0 Answers  


How many types of methods are there in java?

0 Answers  


Categories