The 'static' keyword in java

本文详细解析了静态成员的概念,包括静态变量、静态方法、静态代码块及静态内部类。阐述了它们的特点与使用场景,例如静态变量为所有实例共享,静态方法无需创建对象即可调用等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值