Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are static setter/getters allowed?

I am develoing a Web Application, in that there is a utility method named getData() which I made it as a static. Until now its fine, but this static method named getData() needs some data from setters and getters. So now my question is can we make setter/getters as static?

like image 579
Pawan Avatar asked Nov 17 '11 11:11

Pawan


People also ask

Can we have getter and setter for static variables?

Yes, it's possible and you can do that. There are two kinds of getters and setter functions: static.

Should setters and getters be public?

Usually you want setters/getters to be public, because that's what they are for: giving access to data, you don't want to give others direct access to because you don't want them to mess with your implementation dependent details - that's what encapsulation is about.

Can getters and setters be private?

The reason for declaring the getters and setters private is to make the corresponding part of the object's abstract state (i.e. the values) private. That's largely independent of the decision to use getters and setters or not to hide the implementation types, prevent direct access, etc.


1 Answers

if your Properties are static then Getters and setters will also be static.. its all depends on You..

like image 106
Sumit Singh Avatar answered Oct 29 '22 19:10

Sumit Singh