In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the interview questions for Java initialization and recycling". The content in the article 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 interview questions for Java initialization and recycling.
How are overloaded methods distinguished in 1.Java?
Distinguished by the parameter type and order of the overloaded method.
Note: if the parameter type and order are the same, the compiler will report an error regardless of whether the parameter name is the same or not, and the prompt method has been defined. And can not be distinguished by the return value type, if according to the return value to distinguish, sometimes the program does not need to return value when calling the method, then the program can not determine which overloaded method to call.
two。 Read the following procedure to explain the errors.
Public static void testLong (long I) {System.out.println ("test long");} public static void testFloat (float I) {System.out.println ("test float");} public static void main (String [] args) {testLong (50); testFloat (1.5);}
There is no problem with testLong, because the passed parameter 50 is int, while the receiver parameter is long, and a small range can be automatically converted to a large range of data types; testFloat will not be compiled, because the passed parameter 1.5 is of double type, while the receiver parameter is of float type, and the conversion of a large range to a small range data type requires explicit conversion, that is, testFloat (1.5f).
3. Read the following procedure to explain the errors.
Public static class A {A (int I) {System.out.println ("A (int I)");}} public static void main (String [] args) {An a = new A ();}
After a custom constructor is defined, to use the default constructor, you need to explicitly specify the default constructor, otherwise AA = new A (); cannot be compiled.
4. Read the following program to explain the errors
Public static class A {A () {System.out.println ("A ()");} A (int I) {System.out.println ("A (int I)");} A (int I, int j) {A (); A (I) System.out.println ("A (int I, int j)");}}
When calling other constructors in one constructor, you need to use the this keyword, such as this (); only one other constructor can be called in one constructor, and the statement calling the other constructor needs to be placed on the * * line of the caller (that is, the constructor that issues the calling behavior) statement block.
5. Read the following procedure and write out the execution result.
Public static class A {private int i; private String j; int getI () {return I;} String getJ () {return j;} A (int I) {I = I;} A (String j) {this.j = j }} public static void main (String [] args) {System.out.println (new A (5). GetI ()); System.out.println (new A ("hello"). GetJ ());}
The execution result is:
0
Hello
For I = I; for this statement, it does not change the value of instance variable I, and the default value of I is 0, so the result is also 0. If you need to change the value of instance variable I, it needs to be changed to this.i = I.
6. In a class, several static methods and non-static methods are declared. Please talk about whether the declared static method can access the declared non-static method and explain why?
Static methods cannot access non-static methods because the static method is a method that belongs to the class itself and is determined during compilation, while non-static methods are methods that belong to objects of this class and need to be instantiated before they can be accessed. If you access a non-static method in a static method, you will not be able to compile.
Why can't the 7.static keyword modify local variables?
The variable or method modified by the static keyword belongs to the class and is determined at compile time, while the ordinary variable or method belongs to the object generated by the class and needs to be determined after instantiation. Therefore, if the static keyword modifies the local variables of the method, on the one hand, the method can only be determined after instantiation, and on the other hand, the variables modified by static need to be determined at compile time, which will lead to contradiction.
What is the purpose of 8.finalize ()? When do I need to call this function?
When finalize () is called where memory needs to be freed, the occupied memory will be reclaimed during the next round of garbage collection, and this function is generally not required to be explicitly called.
The garbage collector can only reclaim memory occupied by objects created by the new keyword, so how to reclaim memory that is not used in this way (such as calling C++ local methods)? Then you need to use finalize (). Because the free () function is needed in C++ to free memory, Java programs need to call the finalize () method to free memory when calling C++.
9. List and briefly explain several common garbage collection technologies.
Reference count: each object contains a reference counter, each time it is referenced, the counter is added by 1, and the reference is set to null or destroyed, and the counter is subtracted by 1. The garbage collector polls and reclaims the memory occupied by the object once it is found that the value of the counter is less than 1.
Stop replication: when the garbage collection mechanism is running, the program needs to stop running, move each active object from one heap to another, and the garbage left behind will be recycled.
Tag removal: starting from the stack and static storage areas, find live objects and mark them, and after all the marking process is completed, the garbage is collected.
Thank you for your reading, the above is the content of "what are the interview questions for Java initialization and recycling". After the study of this article, I believe you have a deeper understanding of what the interview questions of Java initialization and recycling 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
© 2024 shulou.com SLNews company. All rights reserved.