1. When a variable is defined 'static', it's called a "class variable', that is, all the objects of that class own that variable. A class variable can be accessed with the class, without creating objects of the class.
2. When a method is defined 'static', it can be called with class without need to create objects. These methods are called 'class methods'. Note that methods declared static cannot access variables without static. They cannot refer to this or super in any way.
3. static block. Code in static block will be executed once when the class is firstly loaded.
4. static nested class. Declared inside another class, has no access to instance-specific data.
本文详细解析了静态成员的概念,包括静态变量、静态方法、静态代码块及静态内部类。阐述了它们的特点与使用场景,例如静态变量为所有实例共享,静态方法无需创建对象即可调用等。
2702

被折叠的 条评论
为什么被折叠?



