0
Can someone please explain the working of public and private variables within a program
2 odpowiedzi
+ 2
public variable can be used anywhere in program
private variabe is bounded to the body of particular function ,class ect.
+ 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