answersLogoWhite

0

Encapsulation is the concept of hiding the implementation details of a class and allowing access to the class through a public interface. For this, we need to declare the instance variables of the class as private or protected.

The client code should access only the public methods rather than accessing the data directly. Also, the methods should follow the Java Bean's naming convention of set and get.

Encapsulation makes it easy to maintain and modify code. The client code is not affected when the internal implementation of the code changes as long as the public method signatures are unchanged. For instance:

public class Employee
{
private float salary;
public float getSalary()
{
return salary;
}
public void setSalary(float salary)
{
this.salary = salary;
}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Why encapsulation is needed in java?

Encapsulation is not needed in Java, or any other language. But it's useful. Encapsulation is used to minimise the number of potential dependencies with the highest probability of change propagation.


How data hiding is achieved in java?

Data hiding in the java is achieved through the use of encapsulation.


Why java is called truly object oriented language?

because java supports three main pillars.....(inheritance encapsulation and abstraction)..... and everything in java is OBJECT......


Why java do not support global variable declaration?

in order to acheive a inheritance and data encapsulation property global variables are not declared in java.


What are the features of core java?

Core java refers to the core or basic concepts of the Java programming language. Things like encapsulation, inheritance, multi-threading, exception handling and other basic feature of java that comes as part of the Java standard edition forms Core Java


What is the definition of Core Java?

Core java refers to the core or basic concepts of the Java programming language. Things like encapsulation, inheritance, multi-threading, exception handling and other basic feature of java that comes as part of the Java standard edition forms Core Java


What term in java is used to indicate that a class's internal state is hidden from its clients?

Encapsulation............Hiding the data from others


What are the features of the core?

Core java refers to the core or basic concepts of the Java programming language. Things like encapsulation, inheritance, multi-threading, exception handling and other basic feature of java that comes as part of the Java standard edition forms Core Java


What is abstraction method in java?

Abstraction in Java or Object oriented programming is a way to segregate implementation from interface and one of the five fundamentals along with Encapsulation, Inheritance, Polymorphism, Class and Object. Abstraction in Java is achieved by using interface and abstract class in Java.


What are basic java features?

features are: 1. Inheritance 2. Polymorphism 3. Data Encapsulation 4. Data Abstraction etc..


Which is the best Book to understand JAVA in short?

You can use Head First Java or Java Complete Reference to learn Java.


What is feture of java?

These are follows: 1-It is a platform independency. 2-Multithreding. 3-polymorphism. 4-encapsulation. 5-inheritence. 6-multitasking.