How can we call private method outside the class in which it is defined? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can we call private method outside the class in which it is defined?

5th Jul 2018, 11:09 AM
Sumit Basu
Sumit Basu - avatar
3 Answers
+ 1
actually... we cant coz of Encapsulation ———————— but here setters and getters come) https://stackoverflow.com/questions/2036970/how-do-getters-and-setters-work
5th Jul 2018, 11:17 AM
Leshark
Leshark - avatar
+ 1
you are right Sumit
5th Jul 2018, 11:33 AM
Pranay Ganguly
Pranay Ganguly - avatar
0
may be if we call that private method from a public method inside that class after creating an object of that class at outside. In this way we can call the private method.
5th Jul 2018, 11:23 AM
Sumit Basu
Sumit Basu - avatar