0

Why is using variables from a class, (specified as public) in the main function risky ?

23rd Dec 2017, 10:30 PM
Dhar.m
Dhar.m - avatar
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.
23rd Dec 2017, 11:50 PM
cHampsonR
cHampsonR - avatar
+ 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 .
28th Dec 2017, 11:32 PM
Dhar.m
Dhar.m - avatar