標籤:storage without for 需要 poi static named err situation
you don‘t get anythin unless you create an object of that class with new, and at that point data storage is created and methods become available.
But there are two situations in which this approach is not sufficient. One is if you want to have only one picec of storage for a particular piece of data,regardless of how many objects are created,or even if no objects are created. The other is if you need a method that isn‘t associated with any particular object of this class.以上是《thinking in java》裡關於為什麼要使用static關鍵字的描述,翻譯過來即使基於以下兩點理由:1.只需要在記憶體中儲存一份資料;2.需要某種不和對象關聯的資料。
of course,since static methods don‘t need any objects to be created before they are used, they cannot directly access non-static members or methods by simply calling those other members without referring to a named object(since non-static members and methods must be tied to a particular object).這句話翻譯過來就是說static 方法中不能直接非static的屬性或者方法。
java基礎知識要點總結之幾個重要關鍵字(關於static、this、final、)