Explain the main characteristics of encapsulation.

What will be an ideal response?

Like procedural programs, object-oriented programs have variables (attributes) and procedures (methods), but the attributes and methods are encapsulated into objects that are then used much like real-world objects. Encapsulation is the technique of packaging an object's attributes and methods into a cohesive unit that can be used as an undivided entity. Programmers sometimes refer to encapsulation as using a "black box," a device you use without regard for the internal mechanisms. If an object's methods are well written, the user is unaware of the low-level details of how the methods are executed; in such a case, the user must understand only the interface or interaction between the method and object. For example, if you can fill your Automobile with gasoline, it is because you understand the interface between the gas pump nozzle and the vehicle's gas tank opening. You don't need to understand how the pump works or where the gas tank is located inside your vehicle. If you can read your speedometer, it does not matter how the display figure is calculated. In fact, if someone produces a new, more accurate speedometer and inserts it into your Automobile, you don't have to know or care how it operates, as long as the interface remains the same as the previous one. The same principles apply to well-constructed objects used in object-oriented programs.

Computer Science & Information Technology

You might also like to view...

________ are three, four, or five small graphic images that are useful for quickly identifying higher and lower numbers within a large group of data

Fill in the blank(s) with correct word

Computer Science & Information Technology

A frameborder value of 1 will display a border that is one pixel wide

Indicate whether the statement is true or false

Computer Science & Information Technology