0

If a constructor is used in a program in Java is getter and setter still relevant to use?

Java programing language question

5th Oct 2020, 4:32 PM
Sunday Othniel
Sunday Othniel - avatar
3 Respuestas
+ 5
Yes, both have different use. Suppose in future you will add 10 attributes in your class then you have to overload the constructor. But if you have setter also you can set them.
5th Oct 2020, 4:44 PM
Raina Dhankhar
Raina Dhankhar - avatar
+ 4
Sunday Othniel Constructor is used to initial the attributes during creation of object. Where Setter are used to set the value of attributes after creation.
6th Oct 2020, 1:04 AM
Raina Dhankhar
Raina Dhankhar - avatar
0
But what's the difference between getter, setter and constructor Raina Dhankhar ?
5th Oct 2020, 9:51 PM
Sunday Othniel
Sunday Othniel - avatar