what is meant by Encapsulation?Explain with an example?

Answer Posted / santhosh kandula


Encapsulation is nothing but hiding the data.By using
encapsulation the ability to modify the code without
without breaking the code the other who use our code. In
Encapsulation we have to pass private members and access
via the public modifiers.


Example : public class EncapsDemo
{
private String str;
public String getString()
{
return str;
}
public void setString(String str)
{
this.str=str;
}
}

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is ehcache in java?

581


Topic- looping,function overloading,nesting ,polymorphism. Aim - to write a function with a name buzz-buds,that will check whether the given numbers are buddies or not on the basis of no. of parameters passed during function calling.

1706


What is profile in java?

497


What is flatmap java?

583


Why we use beans in java?

606






In java thread programming, which method is a must implementation for all threads?

606


Explain the inheritance principle.

598


How do you find lambda?

570


What are microservices in java?

533


can anyone tell me what kind of questions are asked for core java exam in aptech

1525


What do you understand by downcasting?

601


How can the static main method use instance variables?

595


How can I write a program that takes command line input?

551


What is ioexception in java?

643


How do I enable jvm?

551