+ 1

why using seter and getter meths. in place of using the class attrbute itself?

2nd Feb 2020, 3:59 PM
Khaireddine Serdani
Khaireddine Serdani - avatar
10 Answers
+ 6
I couldn't have explained it this well so kindly read this for better understanding. https://stackoverflow.com/questions/1568091/why-use-getters-and-setters-accessors
2nd Feb 2020, 4:12 PM
Avinesh
Avinesh - avatar
+ 5
Denise Roßberg Yes I know. I wanted to know from Khaireddine Serdani 😁😁😁
2nd Feb 2020, 4:54 PM
A͢J
A͢J - avatar
+ 2
Denise Roßberg Probably he is used to call them class fields and not class attributes.
2nd Feb 2020, 4:52 PM
Avinesh
Avinesh - avatar
+ 2
Information hiding.
3rd Feb 2020, 1:15 AM
Sonic
Sonic - avatar
+ 2
Setters can be used to do some sanity checks and prevent illegal modification of attributes.
3rd Feb 2020, 1:16 AM
Sonic
Sonic - avatar
+ 1
Khaireddine Serdani What is class attributes?
2nd Feb 2020, 4:18 PM
A͢J
A͢J - avatar
+ 1
Avinesh Yes. Fields are another name for the same thing.
2nd Feb 2020, 4:55 PM
Denise Roßberg
Denise Roßberg - avatar
2nd Feb 2020, 5:08 PM
Denise Roßberg
Denise Roßberg - avatar
0
🅰🅹 - Sʀ. Sᴏғᴛᴡᴀʀᴇ Eɴɢɪɴᴇᴇʀ The variables. For example public class MyClass{ int a; String s; } a and s are attributes. You can also look here: https://www.sololearn.com/learn/Java/2218/?ref=app
2nd Feb 2020, 4:39 PM
Denise Roßberg
Denise Roßberg - avatar