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

Can an anonymous class be declared as implementing an interface and extending a class in java programming?

0 Answers  


Is a method a function?

0 Answers  


How do I type unicode?

0 Answers  


What is supplier in java?

0 Answers  


What is a method signature java?

0 Answers  






What is null object in java?

0 Answers  


What are invisible components?.

0 Answers  


Is java hashset ordered?

0 Answers  


What is == in java?

0 Answers  


What is the purpose of finalization in java programming?

0 Answers  


Where are the local variables stored?

0 Answers  


What is a stringbuffer?

0 Answers  


Categories