Diff between 'set' and constructor | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Diff between 'set' and constructor

if constructors are used for providing the initial values for the attributes of objects what is the difference between the "set" and "constructor"?

10th Jun 2017, 4:42 AM
Aditya Nandagiri
Aditya Nandagiri - avatar
1 Answer
+ 14
The constructor allows you to set the attributes when you create the object. Ex: ID user = new ID("User", 12387); //Assigns username and idNumber Setters allow you to change an object's attributes whenever you want. Ex: user.setName(Scanner.nextLine());
10th Jun 2017, 5:21 AM
Tamra
Tamra - avatar