In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the citation methods of the java class". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the citation methods of the java class".
1, the active reference of the class, the initialization of the class must occur. When the virtual machine starts, initialize the class where the main method is located
Instantiate an object of a class
Call static members of the class (except for the final constant) and static methods
Use the method of the java.lang.reflect package to make a reflection call to the class
Initialize a class. If its parent class is not initialized, its parent class will be initialized first.
2. the passive reference of the class will not occur the initialization of the class.
When accessing a static domain, only the class that actually declares the domain is initialized. For example, when the static variable of the parent class is referenced through the subclass, it will not cause the subclass to initialize.
Defining a class reference through an array does not trigger the initialization of this class
Reference constants do not trigger initialization of this class (constants are stored in the constant pool of the calling class during the link phase)
Example
When package com.volcano.reflection;// will initialize the class, you should open the test independently except the first comment, otherwise it is inaccurate to public class TestReflection3 {static {/ / 1. When the virtual machine starts, the class where the main method is first initialized will System.out.println ("main method is loaded");} public static void main (String [] args) throws ClassNotFoundException {/ / 2. Instantiating an object will / / new Father (); / / 3. Calling static members of the class (except for the final constant) and static methods will / / System.out.println (Son.a); / / 4. A reflection call to a class using the method of the java.lang.reflect package will / / Class cls = Class.forName ("com.volcano.reflection.Father"); / / 5. Initialize a class, if its parent class is not initialized, its parent class will be initialized first / / new Son (); / / 6. When accessing a static domain, only the class that actually declares the domain will not be initialized / / System.out.println (Father.a); / / both will only load Father / / System.out.println (Son.a); / / because an is a static member of Father / / 7. Defining a class reference through an array will not trigger the initialization of this class. / / Father [] fathers = new Father [10]; / / 8. Referencing constants will not trigger the initialization of this class will not / / System.out.println (Father.B);}} class Father {static {System.out.println ("Father loaded");} static int astat100; static final int B = 300;} class Son extends Father {static {System.out.println ("Son loaded");} static int loaded 200 } Thank you for your reading, the above is the content of "what are the reference methods of the java class?" after the study of this article, I believe you have a deeper understanding of what the reference methods of the java class have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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
Comprehensive Health Service platform based on big data
© 2024 shulou.com SLNews company. All rights reserved.