static field and method in java

来源:互联网 发布:tensorflow中文官网 编辑:程序博客网 时间:2024/06/04 08:05

Called class members: class attributes and class methods.

We can use ClassName.StaticField and ClassName.StaticMethod to access them.

They don’t belong to any instance, so we can’t use this.StaticMember, super.StaticMember.

Note: main method is static, so JVM doesn’t create a instance of the class where main is in. As a result, main can’t access non-static members of the class unless create instance of that class.

static block: when the class is loaded, the static block in that class is executed, and executed for only one time. Usually used to initialized the class.

0 0
原创粉丝点击