Shiqianfeng class war against the North Branch 202 joy

Over and over again knock knock knock again!
Online learning javaEE on the 16th day
learn static static modifier
man of few words said, directly on the picture.
Test sites, the static properties of a single class, a change has changed instance variables can have many copies of a change, it does not affect the other.
Static method can not access non-static properties and methods.
Static modification is static, the whole class total, a change is changed.
When the class is loaded, the static code block is executed only once.  Static code block is really static properties before execution after the execution.
Instead of creating a static method to access the object, but also through the class name, direct access to static members.  sup.m1 () is equivalent to Super.m1 (), sub.m1 () is equivalent to Sub.m1 ().
Because want to see how many objects are created, the whole class to share, so use a static modification variable count.

Released four original articles · won praise 0 · Views 34

Guess you like

Origin blog.csdn.net/weixin_46285316/article/details/104486664