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 |
INTERVIEW QUESTION FOR ANDROID
What is the default access specifier for variables and methods of a class?
Can a final method be overloaded?
Why 1 is not a prime number?
What are the types of statement? explain
what is mean by method signature?
Which one of the following suits the description of a string better: derived or primitive?
we have syntax like for(int var : arrayName) this syntax is to find whether a number is in the array or not.but i want to know how to find that number's location.
What is low level language in computer?
What is meant by class and object in java?
How do you sort in java?
How many types of methods are there in java?