Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个非常简单的问题:静态方法应该对每个对象都有相同的结果吗?
不
public static boolean isEven(int number){ return (number %2 ==0); }
你是什么意思?静态方法不能有this对象,但如果传递不同的参数,它们可能会返回不同的结果。换句话说,a.staticMethodandb.staticMethod肯定会返回相同的结果,但staticMethod(a)andstaticMethod(b)可能会有所不同。
this
a.staticMethod
b.staticMethod
staticMethod(a)
staticMethod(b)