Java static
来源:互联网 发布:浙师大行知学院怎么样 编辑:程序博客网 时间:2024/06/05 04:12
static
members belong to the class instead of a specific instance.
It means that only one instance of a static
field exists[1] even if you create a million instances of the class or you don't create any. It will be shared by all instances.
Since static
methods also do not belong to a specific instance, they can't refer to instance members (how would you know which instance Hello class you want to refer to?). static
members can only refer to static
members. Instance members can, of course access static
members.
Side note: Of course, static
members can access instance members through an object reference.
Example:
public class Example { private static boolean staticField; private boolean instanceField; public static void main(String[] args) { // a static method can access static fields staticField = true; // a static method can access instance fields through an object reference Example instance = new Example(); instance.instanceField = true; }
[1]: Depending on the runtime characteristics, it can be one per ClassLoader or AppDomain or thread, but that is beside the point.
- Java static
- java static
- Java Static
- java static
- Java static
- java static
- JAVA static
- java static
- java static
- Java static
- Java static
- JAVA static
- java static
- java static
- java static
- Java static
- java static
- Java-static
- android 关闭指定的activity
- cordova build android 补充
- transient的作用及使用方法
- shell 编程- -入门篇
- Android SO逆向-数组与指针
- Java static
- ida 使用 问题总结
- EventBus3.0 使用详解(一)
- 项目管理和代码托管平台GitLab
- t3-framework的thememagic能改变那些东西?
- extern -- 全局变量 -- 一种良好的结构
- ORA-08103: object no longer exists
- 微信开发<四> 事件处理
- 在maven的pom.xml中添加<dependency>直接可以下载jar包吗