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
How will you calculate the depth of a binary tree if the tree contains 15 nodes?
What is the use of join method?
Are private methods final?
What is the use of put method?
What is the static block?
What is the difference between the paint() and repaint() methods in java programming?
What is int short for?
What is the core java?
Whats the difference between notify() and notifyall()?
What do you mean by stream pipelining in java 8?
Why webdriver is an interface?
What is function declaration?
Can we use a switch statement with strings?
What is volatile keyword in java
What is volatile data type?