answersLogoWhite

0


Best Answer

By declaring the data private or protected in the class. Private data is accessible to the class and friends of the class. Protected data is the same as private data but is also accessible to derived objects. Public data is fully exposed.

User Avatar

Wiki User

โˆ™ 2012-06-08 00:17:44
This answer is:
User Avatar
Study guides

Data Science

โžก๏ธ
See all cards
4.44
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
9 Reviews

Add your answer:

Earn +20 pts
Q: How does a class accomplish data hiding in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How does a class enforce data-hiding in C plus plus?

In c++, data hiding is enforced in classes using private data members !!! it means that we cant directly access the private data members of a class.


How data hiding is possible within a class in c plus plus?

Data hiding, also known as encapsulation, is where the data is declared private to the class, making it inaccessible outside the methods of the class. Only the methods of the class can access the data. The external view is only what is presented in the public interface via the various accessors. By doing this consistently and correctly, you can change the underlying data representation without changing the public interface, and thus without changing the code that uses the class, You can encrypt the data, for instance, or provide access controls for security purposes.


What are the differences between a struct data type and a class data type in c plus plus?

Structures are public while classes are private by default. A class that is declared fully public is no different to a structure, and therefore breaks the fundamental principals of data-hiding and encapsulation, two of the cornerstones of OOP.


Why c plus plus is not purely object oriented language?

Because C++ has friend functions/class using which we can access the private data members of the class which violates the data hiding property of C++ and in C++ we write main function outside of the class. But in pure object oriented language everything has to be inside the class.


What is class How does it accomplish data hiding in c plus plus?

A class is a description of an object, its attributes, and its methods. Its not a lot different than primitive types, such as int. int a; /* instantiate object of type int and call it a */ person b; /* instantiate object of type personand call it b */ The difference is that person is declared in a class specification, and is potentially much more complex than int. Still, you can think of both in the same context. The attributes (member variables) of a class contain the state of each instance of that class. You can (and usually do) declare those attributes as private, which means that only methods of the class can access them. This is data hiding. With data hiding, you can encapsulate the functionality of a class, exposing only the needed public interface. This way, if you need to change the way a class works internally, such as storing the person's name in unicode string instead of char string, that change can, if the interface is correct, be totally transparent to the user of the class.

Related questions

How does a class enforce data-hiding in C plus plus?

In c++, data hiding is enforced in classes using private data members !!! it means that we cant directly access the private data members of a class.


How data hiding is possible within a class in c plus plus?

Data hiding, also known as encapsulation, is where the data is declared private to the class, making it inaccessible outside the methods of the class. Only the methods of the class can access the data. The external view is only what is presented in the public interface via the various accessors. By doing this consistently and correctly, you can change the underlying data representation without changing the public interface, and thus without changing the code that uses the class, You can encrypt the data, for instance, or provide access controls for security purposes.


What are the differences between a struct data type and a class data type in c plus plus?

Structures are public while classes are private by default. A class that is declared fully public is no different to a structure, and therefore breaks the fundamental principals of data-hiding and encapsulation, two of the cornerstones of OOP.


Why c plus plus is not purely object oriented language?

Because C++ has friend functions/class using which we can access the private data members of the class which violates the data hiding property of C++ and in C++ we write main function outside of the class. But in pure object oriented language everything has to be inside the class.


What is class How does it accomplish data hiding in c plus plus?

A class is a description of an object, its attributes, and its methods. Its not a lot different than primitive types, such as int. int a; /* instantiate object of type int and call it a */ person b; /* instantiate object of type personand call it b */ The difference is that person is declared in a class specification, and is potentially much more complex than int. Still, you can think of both in the same context. The attributes (member variables) of a class contain the state of each instance of that class. You can (and usually do) declare those attributes as private, which means that only methods of the class can access them. This is data hiding. With data hiding, you can encapsulate the functionality of a class, exposing only the needed public interface. This way, if you need to change the way a class works internally, such as storing the person's name in unicode string instead of char string, that change can, if the interface is correct, be totally transparent to the user of the class.


What is the term that describes the hiding of implementation details of objects from each other in a C plus plus class?

Encapsulation.


What is data hidening in c plus plus?

Data hiding is a property that only relevant information is exposed to the user and rest of the informations remains hidden from the user


Is there anything similar between C and C plus plus with reference to data hiding?

No. Data hiding is a feature of object oriented programming. C does not support OOP, and therefore has no private member access. All members are public in C.


What are the properties of class in c plus plus?

The properties of a class are its member methods (functions and operators). The member data are known as the attributes of the class.


Difference between c plus plus class and c structures?

A C struct can contain only data; a C++ class can contain both data and functions.


Disadvantages of friend function in c plus plus?

The only disadvantage is misuse. When used correctly, friend functions extend a class interface. But if a friend function undermines encapsulation, then there is a clear design flaw in the class, and the use of a friend function should be reconsidered. It coincide the concept of data hiding


What are the components of visual c plus plus?

The simple answer is C, classes and objects. The components of C are data types and functions. A class combines data with the functions that operate upon that data, while an object is an instance of a class.

People also asked

How class accomplish data hiding?

View results