Is we can use our own method for getting and setting private attributes or methods | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is we can use our own method for getting and setting private attributes or methods

Why we can not or should not use our own method for getting and setting private attributes or method.Using self created method also works for getting and setting attributes and methods so what's the problem in that.I had used my own method name. For Example: https://code.sololearn.com/cLvAzJJkP2Um/?ref=app

13th Jul 2020, 3:12 AM
Akash
Akash - avatar
2 Answers
+ 2
Akash We can make our own setter and getter method of members. There will be no issue but we can't recognise that what data we are going to set or get. For example as you created your own method which is not on the name of members and only you know that method works to set data for color but if other person will come to work then he/she will not get in which setter method we have to use to set data. There will be no problem for single or 2 or 3 members but if there will be more than 10, 20, 30 then it will be not good to create own method for each members.
13th Jul 2020, 4:20 AM
A͢J
A͢J - avatar
+ 1
It's just an agreement like in the main method the parameter will be called args but it actually can be called however you want
13th Jul 2020, 4:07 AM
Eliya Ben Baruch
Eliya Ben Baruch - avatar