I am wondering when to use static methods? 我想知道什麼時候使用靜態方法? Say if I have a class with a few getters and setters, a method or two, and I want those methods only to be invokable on an instance object of the class. 假設我有一個帶有幾個getter和setter的類,一個或兩個方法,而且我但願這些方法只能在該類的實例對象上調用。 Does this mean I should use a static method? 這是否意味着我應該使用靜態方法? this
eg 例如 spa
Obj x = new Obj(); x.someMethod
or 要麼 .net
Obj.someMethod
(is this the static way?) (這是靜態方式嗎?) code
I'm rather confused! 我很困惑! 對象