From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

What is encapsulation?

What is encapsulation?

- [Instructor] Encapsulation is one of the forming principles in object-oriented programming. It refers to the idea of binding an object state and behavior together into one unit. In other words, encapsulation is about wrapping data and code acting on that data together. This may sound familiar and it should. In the last chapter, we bound together data and methods in the form of a Java class. Now we're giving this idea a formal name, encapsulation. While we saw the beginnings of how to perform encapsulation by pure organization of the code, in this chapter, we'll expand upon that concept, as well as look at some of the benefits of this approach. One benefit is we can prevent classes from being tightly coupled. This means we can easily modify one class, either in the data it contains or its behaviors, without affecting the rest of the program. However, this can only happen if we have a clear interface between the class and the…

Contents