+ 1
why using seter and getter meths. in place of using the class attrbute itself?
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
+ 5
Denise RoĂberg Yes I know. I wanted to know from Khaireddine Serdani
đđđ
+ 2
Denise RoĂberg Probably he is used to call them class fields and not class attributes.
+ 2
Information hiding.
+ 2
Setters can be used to do some sanity checks and prevent illegal modification of attributes.
+ 1
Khaireddine Serdani What is class attributes?
+ 1
Avinesh Yes. Fields are another name for the same thing.
+ 1
Khaireddine Serdani
Here are some posts. Please use the search bar next time to avoid duplicates.
used keywords: "setter getter", "encapsulation"
https://www.sololearn.com/Discuss/572487/?ref=app
https://www.sololearn.com/Discuss/606528/?ref=app
https://www.sololearn.com/Discuss/681795/?ref=app
https://www.sololearn.com/Discuss/1293797/?ref=app
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