0

Can someone please explain me what is setName() and what is getName()?

I am a beginner in Programming and I want to understand those words.

7th Jul 2017, 9:54 AM
Bharath Naidu Yenumula
Bharath Naidu Yenumula - avatar
1 Answer
+ 1
These ones are setter and getter. Usually used in classes to manipulate its fields. Such code uses encapsulation and allows safely change the object. With simple public members you can do such things car.speed = 300; and it will break the logic or anything else if car can only speed up to 100 mph. Setters usually check their input parameters in such cases.
7th Jul 2017, 12:15 PM
soman