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 access modifiers can be used for variables?
What modifiers are allowed for methods in an interface?
What is the multilevel inheritance. and also give the Example of it ?
what is mutability?which one is mutable String or StringBuffer?and why?give examples of each which shows the mutability of each String or StringBuffer
What are the types of methods in java?
What are the three parts of a lambda expression? What is the type of lambda expression?
Can you declare the main method as final?
why applet doesn't have main? isn't possible a program with out main?
what is meaning of JIT?
Difference between Superclass and Subclass?
Write java program to reverse string without using api?
Can arraylist contain null values?