Follow Our FB Page << >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

What is encapsulation? Elaborate with example?

What is encapsulation? Elaborate with example?..

Answer / devarathnam.c,kotagudibanda,ka

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.
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

Observe the above program we are combining both data and
methods into a single unit(EcapTest). I hope i met your

Is This Answer Correct ?    23 Yes 5 No

Post New Answer

More Core Java Interview Questions

Which data type is class in java?

0 Answers  

Why isn’t there operator overloading?

0 Answers  

What is mean by exception?

0 Answers  

Is a char always 1 byte?

0 Answers  

How do you test a method for an exception using junit?

0 Answers  

How will you convert an ArrayList to Arrays?

4 Answers   KPIT,

How to obtain a performance profile of java program

0 Answers  

What is Locale class?

1 Answers   MySoft,

What are keywords and reserved words in java?

0 Answers  

What is the formula to calculate percentage?

0 Answers  

What is instance example?

0 Answers  

What is thread safe java?

0 Answers