0
Why is using variables from a class, (specified as public) in the main function risky ?
2 Antworten
+ 2
It is better practice for larger codes where there is a possibility of variables changing or class attributes changing. For example, if you have a bank account class, you want the balance attributes to be private so it cannot be changed with going through a certain process to be able to change it. If this didn't clear it up, sorry.
+ 1
Using a public variable can get the code messed up easily as changes to the variable within the program affect the variable instances entirely in the class .