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 module in project?
Is java free for commercial?
Does substring create a new object?
What is overloading and overriding in java?
Do we have pointers in java?
Is java still necessary?
What is navigable map in java?
What do you mean by inner class in java?
What do you understand by the bean persistent property?
Explain the inheritance?
What are the advantages and disadvantages of reference counting in garbage collection?
Is space a character in java?
In which language java is written?
what is comparable and comparator interface?
Why isn’t there operator overloading?