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

Is eclipse a jdk?

493


I want to control database connections in my program and want that only one thread should be able to make database connection at a time. Define how can I implement this logic?

579


How do I enable java in google chrome?

442


What type of parameter passing does java support?

455


How do you check if java is installed on windows command prompt?

435






How do I enable java in firefox?

472


What is difference between map and flatmap in java 8?

461


Can we write lambda without functional interface?

447


How do I run a java project in netbeans?

463


What is scrollable resultset in java?

470


What is microservices java?

456


Why dependency injection is used in java?

463


What is the difference between lambda expression and anonymous methods?

460


What is flatmap in rxjs?

476


What is the point of lambda expressions?

470