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
Can private members of a base class are inheritable justify?
What is charat java?
How will you call an Applet using Java Script Function?
What is keyword and identifier?
What is the importance of finally block in exception handling?
What is variable and its types?
What is maximum size of arraylist in java?
Can size_t be negative?
what is function overloading in java?
Does java support Operator Overloading?
What about interrupt() method of thread class ?
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
What is an eror in java?
What is the default value of the local variables?
What function extracts specified characters from a string?