answersLogoWhite

0

Java Encapsulation

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

Assumptions of 2 phase commit protocol?

to implement real-world entities more and more in computer language and to protect datas we require c++.c++ is basically an object oriented programming language.there are special features which are not present in c such as data encapsulation,data abstraction,polymorphism,inheritance etc.by encapsulation ,we can bind different data types in single unit.by data abstraction ,we can protect our datas.by polymorphism ,we can overload an operator.and by inheritance,we can inherit the properties of the base class.


What is a real world example of a fjord?

A fjord is a real world example of a fjord! They exist in the real world.


What is a real world example of circumference?

The Equator is a real world example, being the circumference of the Earth.


What is the real world example?

Of what?


What is a Real world example of conservation'?

Example is too omitted to be real. Example is much more unresponsive


What is a real world example of a pentagon?

where could you find a pentagon in the real world


What is a real world example of a prime number?

2 is a real world prime number.


What is a real world example of a sample?

a example of a hendecagon is a hedecagon


Can you give me some REAL world examples?

A real world example of what? Math in general? Geometry nets? Name the math concept and it'll be easier for readers to give you a real world example.


What is a real world example?

A real-world example of poetry can be anything that focuses on a real event that happened. For example, it could be about the Twin Towers, Great Wall of China, or about the wars the USA. had to go through.


What does number line means?

A picture of a straight line that serves as abstraction for real numbers.


What are examples of intersecting lines in the real world?

Roads are an example of intersecting lines in the real world.