How to access private data of a class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to access private data of a class?

26th Aug 2018, 12:24 AM
Dura
Dura - avatar
5 Answers
+ 11
Use a getter or setter method 😄🤗🙆‍♂️💖
26th Aug 2018, 12:30 AM
NimWing Yuan
NimWing Yuan - avatar
+ 3
By creating and using public methods that can access the data of that class.
26th Aug 2018, 12:28 AM
Steppenwolf
Steppenwolf - avatar
+ 3
Alternatively, for C++, a friend function introduced in class definition can access a class' private members, as if it was a method of the class itself.
26th Aug 2018, 2:46 AM
Ipang
+ 1
Thanks.
26th Aug 2018, 12:48 PM
Dura
Dura - avatar
+ 1
to access private method? to write the key word with you mathod name { set or get } ste keywords used to assign value. get keywords used to print/show value.
27th Aug 2018, 6:55 AM
ALi Ahamed
ALi Ahamed - avatar