In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Java object method call execution process is what", in daily operation, I believe many people in Java object method call execution process is what kind of problem there are doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "Java object method call execution process is what" doubts help! Next, please follow the small series to learn together!
Object method call execution process
The compiler looks at the declared type and method name of an object. Suppose x.f(param) is called, and the implicit parameter x is declared as a C class object. It should be noted that there may be multiple methods with the method name f but different parameters. In this case, the compiler will list all the methods with the method name f in the C class and the methods with the access attribute public and the name f in the superclass.
Next, the compiler looks at the type of argument provided when calling the method. If there is one method named f that exactly matches the type of argument provided, that method is selected. This process is called overload resolution.
If it is a private method, static method, final method, or constructor, then the compiler knows exactly which method should be called. We call this static binding, which corresponds to the fact that the method called depends on the actual type of the implicit parameter and implements dynamic binding at runtime. For example, call a method f (String).
When the program runs, and methods are invoked using dynamic binding, the virtual machine must invoke methods of the class most appropriate for the type of object referenced by x. Suppose that the actual type of x is D, which is a subclass of C. If the f (String) method is defined in subclass D, call it directly, otherwise search for methods in class C, and so on.
The overhead of calling methods is so high that the virtual machine defines a method table for each class that lists all the method names and signatures, so that when the method is actually called, the virtual machine can directly face this table.
Several ways to call methods
Generally, in Java, there are three ways to invoke methods.
the first
By object name. Method name, which is the most common and common way to call.
the second
Constructor methods are called with the new keyword, which is the way to instantiate an object.
a third
By class name. Method name invocation, used when the method to be invoked is static. In line with actual operation, the following examples are attached:
At this point, about "Java object method call execution process is how to learn the end, hope to solve everyone's doubts." Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.