What are instance variables please? Also, is this a good explanation for Encapsulation:

Encapsulation or information hiding is all about hiding the details of the implementation of the interface. Encapsulation is used to prevent users from viewing the inner workings of the interface.

A real life example of Encapsulation is we know that we can breath without knowing how our bodies performs it.

In C++ classes have two parts, the interface and the implementation. The interface is the implementation for the external interface (what the user sees) i.e. a human being. The implementation is code that performs all the operations, walking, eating, talking etc. The general user should not be able to see the inner workings of the interface.

Encapsulation is used for many reasons in C++ one of the main reasons is so that the implementation code can be changed without affecting the interface. Encapsulation also prevents the program the program from relying on other programs which one small change could have a massive effect.

Encapsulation can also help improve the performance, fix bugs and bring together coding. `


Thanks for any advice =)

What are instance variables please?

class Example
{
    static int x; // static variable
    int y;        // instance variable
};

Instance variables are data members of a class where each object has a separate copy. They are distinct from static variables where every object of a class shares one copy.

Encapsulation is used to prevent users from viewing the inner workings of the interface.

I would say encapsulation is used primarily to prevent users from needing to know the inner workings to use objects of the class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.