+ 1
Any particular reason why you wouldn't just keep everything public?
6 Respuestas
+ 3
Making a method private is an indication that your code is perfect and will never need to be fixed or updated. Instead, use protected. When you learn about inheritance, you will learn that protected methods can be overridden. This allows future developers working with your legacy code to make changes without changing your original class structure (as changes to the original class methods could break other implementations of the class they are unaware of).
+ 1
To be able to organize your code and make it less buggy, also you possibly not work on a project with yourself, so you should use these access modifiers like protocols..
Further explanation here: http://qr.ae/RO89sU
+ 1
to minimize the error caused..by external access.
0
you can define variable whatever u want bt it depends upon situation
0
When methods or variables don't want access by other classes(client) declare as private
0
it reduces the changeability of your code.. because public fields tend to link you to a particular implementation and limit your flexibility in changing your code