0

Can someone please explain the working of public and private variables within a program

21st Jun 2017, 10:59 AM
Vishal
Vishal - avatar
2 Réponses
+ 2
public variable can be used anywhere in program private variabe is bounded to the body of particular function ,class ect.
21st Jun 2017, 11:44 AM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar
+ 1
Here is code you can try and play with. When you create a private function, it means that other classes cannot access it. It is done so that the class can work properly and it doesn't make the programmer confused. Public classes however can be accessed from other classes. In this example I want you to try and do func.runFunction(); If it fails, it's because the myFunction class does not allow you to access the runFunction method, because it is set to private. https://code.sololearn.com/cZnqptExpwKU/?ref=app
21st Jun 2017, 12:53 PM
Limitless
Limitless - avatar