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 |
What happens if main method is not static?
Differentiate constructor and a method and how are it be used?
What is the main purpose of java?
What is implicit object in java?
What is scope & storage allocation of static, local and register variables? Explain with an example.
Does printwriter create a file?
What is difference between null and void?
Why are there no global variables in java?
How do you get length in java?
How many bytes is a url?
Difference between class#getinstance() and new operator ?
What is append in java?