首页 > 代码库 > java基础知识要点总结之几个重要关键字(关于static、this、final、)

java基础知识要点总结之几个重要关键字(关于static、this、final、)

          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、)