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 protected access modifier?
How do I enable java in safari?
What are the differences between graph and tree?
Is empty string in java?
What sorting algorithm does javascript use?
What is unicode used for?
What is data and its types?
In case of inheritance what is the execution order of constructor and destructor?
What is vector capacity in java?
What is the indent key?
How many bytes is a char in java?
what is synchronization? : Java thread
What about main() method in java ?
How do you implement polymorphism in our day to day life?
Is it safe to install java on my computer?