Niuke.com Java Wrong Question Summary (3)

table of Contents

One, class overload

Second, the algorithm structure

Three, keywords

Four, abstract class

Five, the constructor

Six, local internal class

Seven, constant pool


 

One, class overload

Analysis:

  • Overload: different parameters with the same name, the return value is irrelevant
  • Overwrite rewrite: same name and same parameter

 

Second, the algorithm structure

Analysis:

  • The algorithm structure includes:
    • 0 or more inputs
    • 1 or more outputs
    • There are a finite number of processes

So storing data is not counted as an algorithm structure

 

Three, keywords

Analysis:

  • A: Native is to call native method libraries (such as operating system low-level functions), which can be implemented in C or C++.
  • B: import is used to guide the package statement, and package can appear before it to declare the package.
  • C: Modifiers of interface methods can be: public, abstract, default, static (the latter two need to have {}).
  • D: The construction method can use private, protected, default, private.

 

Four, abstract class

Analysis:

  • A: When there are abstract methods in a class, it must be declared as an abstract class
  • B: When the class is a subclass of an abstract class and does not provide any details or method body for any abstract method, it must be declared as an abstract class
  • D: When a class implements an interface and does not provide any details or method body for any abstract method, it must be declared as an abstract class

 

Five, the constructor

Analysis:

  • A: The constructor has no return value.
  • B: Multiple class constructors do not necessarily have the same name as the public class, because each class can have a constructor, and the function name is the same class.
  • C: The constructor can have any number of parameters.
  • D: Each class has a constructor by default, and there can be one or more constructors.

 

The construction method is a special method with the following characteristics.

  1. The method name of the constructor must be the same as the class name.
  2. The constructor has no return type, nor can it be defined as void . The method type is not declared before the method name.
  3. The main function of the construction method is to complete the initialization of the object. It can pass the parameters when defining the object to the domain of the object.
  4. A class can define multiple constructors. If no constructor is defined when the class is defined, the compiler system will automatically insert a default constructor with no parameters. This constructor does not execute any code.
  5. The construction method can be overloaded, with the number, type, and order of the parameters.

 

Six, local internal class

Analysis:

Local inner classes are placed in code blocks or methods, cannot have access control modifiers, and cannot be modified with static

 

Seven, constant pool

Analysis:

The runtime constant pool is in the method area,

Before JDK1.8, the permanent generation method was used to implement the method area, which belongs to thread sharing;

After JDK1.8, the meta space replaces the permanent generation method to implement the method area, and the runtime constant pool is also placed in the meta space.

The nature of the metaspace is similar to the permanent generation, and both are the realization of the method area in the JVM specification.

However, the biggest difference between metaspace and permanent generation is that metaspace is not in the virtual machine, but uses local memory.

 

The runtime constant pool mainly stores various literals and symbol references generated during compilation.

The so-called runtime constant pool is actually to put compiled class information into an area at runtime to dynamically obtain class information.

Runtime constant pool is complete after the class is loaded, the symbols of each class constant pool reference value dump runtime constant pool , that is, each class has a runtime constant pool , after parsing class , Replace the symbolic reference with a direct reference, which is consistent with the reference value in the global constant pool.

The runtime constant pool is part of the method area. In addition to the description information of the class version, fields, methods, interfaces, etc., the Class file also has constant pool information (used to store various literals and symbol references generated during compilation)

Guess you like

Origin blog.csdn.net/weixin_39478524/article/details/114993021