In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Why can't there be this and super in the static method? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Because the static method and the instance (object) of the class are two different things, it is only initialized when the class is loaded (that is, when compiling or when the javac command is used) and is called the class-level variable (belonging to the class), while the instance of the class is initialized when the program is running (that is, when the Java command is used), which is called the object-level variable (belonging to the object).
This represents the current instance of this class, super represents the current instance of the parent class, static belongs to the class, this is an object of the class, of course, cannot call him, static is awesome, only the class name can call it, static is called static method, also known as class method, that is, when the program starts, a piece of memory space will be allocated for this method, so this method can be called at any time.
Non-static methods cannot be called in static methods unless you instantiate that class first. If the this keyword is used in the static modified method, and this keyword cannot point to the appropriate object; so we also say that static members cannot directly access non-static members; jvm classful loader, the first time the class is loaded to execute the staticdomain in the class, jvm will specifically divide a memory area to the static block, which can become a static area and belong to this class. The this pointer is the object that points to the class, and when the object is instantiated, jvm allocates memory to a specific object in the heap area, and the this pointer points to this object. The static field in the class always allocates memory in the static area, and this points to the heap area, so it cannot be called. Static belongs to the class. This is an object pointer
This is the answer to why there are no this and super questions in the static method. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.