+ 1

Any particular reason why you wouldn't just keep everything public?

22nd Jan 2016, 10:38 PM
Hamza
Hamza - avatar
6 Answers
+ 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).
23rd Apr 2016, 1:39 AM
Chris
Chris - avatar
+ 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
24th Jan 2016, 1:52 AM
Ahmed Lo'ay
Ahmed Lo'ay - avatar
+ 1
to minimize the error caused..by external access.
8th Feb 2016, 8:59 PM
Khurshid wali
Khurshid wali - avatar
0
you can define variable whatever u want bt it depends upon situation
18th Feb 2016, 4:21 PM
BasanaGouda Mp
BasanaGouda Mp - avatar
0
When methods or variables don't want access by other classes(client) declare as private
10th Apr 2016, 11:49 AM
Hemanth S
Hemanth S - avatar
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
13th Sep 2016, 5:53 PM
Teja Naraharisetti
Teja Naraharisetti - avatar