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 we extend singleton class?
What are the two main uses of volatile in Java?
What is meant by oops concept in java?
How do you create a bulleted list?
What is empty string literal in java?
What are the types of arrays in java?
What is java full form?
What is functional interface in java example?
What about main() method in java ?
Where is java located?
How is java created?
Is string passed by reference in java?
What is meant by structural programming?
What is Java Annotations?
How can we access some class in another class in java?