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
What is use of map in java?
What is passed by reference and pass by value ?
How are variables stored in memory?
What are java threads?
What are the different types of sorting in java?
Why main method is called first in java?
How do you create immutable object in java?
Why synchronization is important?
Which sorting is used in arrays sort in java?
Can you explain the cs option of java interpreter?
Explain the difference between serializable and externalizable in java?
What are the different tags provided in jstl?
What is vector?
What is the order of arraylist in java?
Why is core java important?