Common Interview Questions finishing --Java foundation Series

1. Object-oriented three characteristics
of object-oriented three basic characteristics: encapsulation, inheritance, polymorphism;
the Java language, object-oriented, the minimum unit for the class.
Packaging: Packaging is to hide all hide things, provide only the most simple programming interface to the outside world;
Inheritance: Inheritance is the process of creating a new class of information to be inherited from an existing class;
Polymorphism: Polymorphism refers to the different sub-types allowed objects respond differently to the same message.

2. Create the way the object
(1) to create an object using the new statement is the most common way
(2) the use of reflection means, call the newInstance () method or java.lang.reflect.Constructor java.lang.Class class
(3) clone method calls the object need to implement Cloneable interface
(4) the use of anti-serialization means and readObject method java.io.ObjectInputStream object
(5) create a sub-class object, if the parent object is not created ......
which 1,2,5 constructor will call, in the memory 3 is a photocopy of an existing object so it will not call the constructor, the object 4 is restored from the file will not call the class constructor;
the Class.newInstance only call no reference constructor; Constructor.newInstance can be called with a parameter and private constructor;
the Employee EMP = (the Employee) the Class.forName ( "com.test.Employee") the newInstance ();.
or
the Employee = Employee.class EMP. newInstance ();

Constructor <the Employee> = Employee.class.getConstructor constructor ();
the Employee EMP2 Constructor.newInstance = ();

whenever the clone call an object method, the JVM creates a new object, the object will copy all the contents into the front; objects created with the clone method does not call any constructor; to use the clone method, we need to implement the Cloneable interface and achieve its defined clone methods
Employee emp3 = (Employee) emp2.clone ( );

to deserialize an object, we need to let the class implements serializable interface;
ObjectInputStream in = new new ObjectInputStream (new new FileInputStream ( "data.obj"));
the Employee emp4 = (the Employee) in.readObject ();

3. What is the serialization and de-serialization of objects, where used, how
serialization in Java refers to the object into a byte sequence to said sequence of bytes containing data information of the object, the object after a serialization may be written to the database or the file may also be used for network transmission. Generally when we use cache cache (memory is not enough space there may be local storage to the hard disk) or remote call RPC (network transmission), we often need to get our entity class implements Serializable interface, the purpose is to let it be serialized (interacting parties a common standard);
the ultimate goal is to serialized deserialized, restored to the original Java objects, so the sequence of bytes serialized Java objects are to be restored, this process is deserialized;
Once the variables are modified transient, variable object persistence will no longer be part of the variable content after serialization can not gain access. May be considered after the persistent object deserialized, the variable will be transient as modified in accordance with the ordinary class member variables are initialized;
a static variable regardless of whether the modification is transient, not be serialized because the class level;
Finally, why else it is serialized it, mainly in order to save storage space.

4. The principle of JVM memory model
in Java is both a compiled language, is an interpreted language: Java source code is compiled into .class files by the javac command, this byte code file does not face any platform, only for the JVM (Java Virtual Machine); JVM Java is a key part of the cross-platform, which provides exactly the same up to the interface of Java bytecode programs, and interfaces down to adapt for different platforms is different from each other, provide specific platform-specific machine code, using java command interpreter execution;
the program counter, the virtual machine stack, native method stacks three regions with the threads born, with the threads off, so the memory allocation and recovery of these areas are equipped with certainty, we do not need too much to consider recycling question, because the method ends or at the end of the thread, just as the natural recovery of the memory; and Java heap allocation and recovery methods zone area and is dynamic, is the need to focus on the part of the GC.

5. GC Principle
To request a garbage collection, related objects can be set to null or call System.gc (), but the latter will seriously affect the performance of your code, because generally every time an explicit call to System.gc () will stop all in response, to check for recyclable objects in memory, so that the normal operation of the program will cause a great threat. In addition, it calls the method does not guarantee that the JVM garbage collection immediately, just to inform the JVM to garbage collection, recycling or not completely determined by specific JVM, doing thankless;
Garbage collector is usually as a separate daemon thread running low priority, unpredictable circumstances of heap memory have died a long time without the use of cleared and recycling;
there are two algorithms can determine whether the object is alive :
(1) reference counting, but it is difficult to solve the case of mutual circular reference between two objects;
(2) reachability analysis, in the mainstream to achieve mainstream commercial programming language (such as our Java), the It is determined by reachability analysis algorithm whether the object is alive;
pile points with the old Cenozoic era, specific operational procedures:
the new generation: contains Eden and two Survivor, just create a new object in Eden, the experience a Minor GC, Eden live objects in the first block will be moved to the Survivor Space S0, Eden emptied; Eden et zone again is full, then trigger a Minor GC, Eden and live objects S0 is again fed to the second block Survivor space S1, S0 and Eden are cleared, then the next round of S0 and S1 switch roles, so on ad infinitum. If you copy the number of objects up to 16 times, the object will be sent to the old era;
associated with garbage collection JVM parameters:
-Xms / the -Xmx - Maximum size of the initial heap size / heap
-Xmn - the new generation of the heap size (also set XX: NewSize = XX: MaxNewSize) , the actual space available Survivor = Eden + 1 th, i.e.,% 90
-Xss - stack size for each thread, in general, if not very deep, then the stack, 1M definitely enough with the
-XX: NewSize / -XX: MaxNewSize - set new generation of size / Cenozoic maximum size
-XX: NewRatio - the proportion of the new generation and the old age, represents the new generation of 1/3 of the entire heap space, accounting years old 2/3
common garbage collection methods:
Clear labeling method: This is the most basic garbage collection algorithm is divided into two stages mark and clear, it is the idea of what is to be recycled object tag, then uniform recycling. This method is very simple, but the efficiency is not high, marking and removal efficiencies are very low. In addition will generate a lot of discrete memory fragmentation, resulting in the allocation procedure after a large object is not enough contiguous memory prematurely trigger a GC operation;
replication algorithm: In order to solve the efficiency problem, replication algorithm according to the available memory capacity is divided into two equal parts, and then uses only one of which, after running out of memory when a further copy live objects to the second memory block, after which time a clear finish of memory, then the second block copy objects to the first piece. However, this approach is too costly memory, each substantially half the memory to be wasted; then the algorithm is improved, the memory area is no longer 1: 1 to divide, but the memory is divided into 8: 1 : 1 three parts, a larger share of the memory area is Eden, the remainder being two smaller memory region is called Survior region, each region will be preferentially used Eden, Eden area full if the object will be copied to the memory area on the second block and then clear the Eden area, if too many objects alive at this time, so that Survivor is not enough, these objects will be copied to the old era by allocating guarantee mechanism;
tags to organize method: this method is mainly to solve the mark clearance method produces a lot of memory fragmentation problems. When objects higher survival rates, but also solve the problem of efficient replication algorithm. It differs from the target is cleared when the first object is moved to one end of the recoverable, then clear out the objects other than the end border, so that a memory fragmentation is not generated, but increases the dwell time;
generational collection method: Now most virtual machine garbage collection in this way, it is based on the life cycle of the object, the heap into the new generation and the old era. In the new generation, because of the short lifetime of the object, there will be a large number of objects recovered each time to die, then the time on the use of replication algorithm, the new generation is divided into Eden and two Survivor, the default size ratio 8: 1: 1. The old era of objects higher survival rates, there is no extra space is allocated guarantee, so you can use tags to organize law or mark clearance method.
Large objects directly into the Old Year: JVM has two parameters -XX: PretenureSizeThreshold, so that the object is larger than the set value directly into the old era, in order to avoid a lot of memory replication occurs between Eden and Survivor areas.
Java objects to null after use and will not reduce the memory footprint, set to null just point to the stack reference to null, but new objects out still exists in the heap, the stack will be no need to wait until the point when the GC algorithm called Object to recover lost.

6. The collection of Java classes which in
Java can be divided into a set of Set, List, Queue, Map four kinds of systems;
the Set: Representative disorder not repeat;
List: Representative orderly and repeatable;
Queue: Queue represents a to achieve the set;
the map: represents a set of mappings.
There are two set of Java interfaces derived out: Collection and Map, Collection interface is the parent interface Set, List, Queue interfaces;
Set Collection with basically the same, there is no other means to provide additional, in fact, it is the Collection Set, but behaves slightly different, set not contain duplicate elements, added to the collection in the same object twice, the second operation will fail, add return false;
List collection allows the use of repeating elements, the elements can be accessed through the specified position index;
the relationship between the Map and set: If the Map in all key put together look, they make up a Set collection (all the key did not order, do not repeat between key and key), actually Map does contain a keySet method, users in all key return Map Set consisting of a collection;
Map and List of the relationship: If the Map to see all the value put together, they form a List, can be repeated between the elements and the elements, each element can find the index, but the index is no longer in use Map integer value , but to another object as an index.

7. The difference with the ArrayList LinkedList
Both allow null elements;
internal ArrayList implementation is based on the internal dynamic array Object [], so Conceptually, it is more like an array, but the implementation is based on the internal LinkedList recording of a set of connection , so it is more like a linked list structure. ArrayList more suitable get and SET, since LinkedList nature doubly linked list is required to find the head movement of the pointer, and ArrayList can be directly indexed by serial number elements; LinkedList more suitable add and remove, because ArrayList need to move data (array end add properties directly also high, but if inserted in accordance with the subscript, remove elements, we need to move some of the affected elements by Arrays.copyof function, performance deterioration);
ArrayList when to increase the data will be called ensureCapacity methods to ensure adequate capacity. When capacity is not enough, the new capacity is set to 1.5 times the capacity of the old (default capacity of 10), if not enough capacity to directly set to the desired capacity, followed by Arrays.copyof method copied into the new array element. Therefore, when the capacity is not enough, each time adding elements need to copy the original elements to a new array, very time consuming, and therefore propose to use ArrayList in the know in advance where the number of elements, otherwise use LinkedList;
space ArrayList of waste mainly reserve a certain capacity space at the end of the list of the list, while LinkedList space spending is reflected in each of its elements need to consume considerable space on the storage density is, ArrayList is better than the LinkedList;
In short, when the operation is to add the data behind a column of data, rather than in the front or in the middle and requires random access to its elements when using ArrayList will provide better performance, when the operation is added to a front or intermediate data or when you delete data, and access to its elements in the order, you should use a LinkedList.

8. understanding of HashMap
(. 1) of the HashMap key feature is the ability to quickly find by value;
(2) HashMap based arrays to implement hash table, like the memory array, index array like the memory address ;
(. 3) the HashMap is a record for each Entry <K, V> objects, is stored in the array objects, which contains the key, value, hash, next four structural elements;
(. 4) a hash function for the HashMap (put operation): when the key is empty, the method by putForNullKey element at the very beginning position (table [0]), or transmitted to the key according worth hashCode (int hash = key.hashCode () ;), and then use this hashCode operation with the length of the array, int obtain a value is to be stored in a location in the array Entry (subscript);
(. 5) the HashMap resolve the conflict: a chain address method, each object has a reference Entry next linked list to point next Entry (if the chain length exceeds the threshold 8, converted into a red-black tree put list, the list is less than a length of 6, red-black tree put back list);
(6) filling the HashMap factors: default 0.75 (needed for determining whether HashMap capacity expansion, expanded to twice its original, default HashMap length is 16);
(7) HashMap the get Operation: When the key is empty, a position directly to the first hash table lookup table [0] corresponding to the list, according to the key or the calculated hash value (array subscript), after acquiring the corresponding Entry, and then determine Entry in the key, hash value or whether the comparison with the same're looking for, the same is returned by equals value, otherwise traverse the list until you find it, otherwise return null (in the HashMap, null is returned by the get method, this may not be the HashMap key, it may be corresponding to the key is null, the method can not be determined by the existence of a key to get the HashMap required containsKey method);
(. 8) HashMap not thread-safe, multi-thread concurrent environment and may be employed under contract of ConcurrentHashMap, or using the following initial mode: m = the Collections.synchronizedMap the Map (the HashMap new new (...));
(. 9) the HashMap implements serializable interface, support serialization, implements the Cloneable interfaces, be cloned.

9. The relationship of the equals method hashCode
presence hashCode method is to reduce the number of calls equals method to improve the efficiency of the program;
the results obtained if the equals method to true, the object hashCode two values must be equal;
result is obtained if the equals method false, two different objects are not necessarily the hashCode;
if two objects hashCode values ranging equals method must result is false;
if the two values are equal objects hashCode, equals a result obtained by the method known.
When rewriting the equals method, you must override hashCode methods.

10. The difference between HashMap and HashTable methods
(1) and both storage structure conflict resolution is the same;
(2) The default is 11 HashTable without specified capacity, and HashMap is 16; the bottom is not required HashTable capacity of the array must be an integer power of 2, and HashMap requires some integer power of 2;
(. 3) in the HashTable key and value are not allowed is null, the key and value in the HashMap allow null (the only one key is null, there may be a plurality of value is null); but if an operation similar put (null, null) in the HashTable, the compiler may likewise be as key and value are of type Object, but runtime a NullPointerException is thrown;
(4) HashTable expansion, the capacity becomes 2 times the original +1, while HashMap expansion, the capacity becomes 2 times the original;
(. 5) HashTable calculated hash value, the direct use of the key the hashCode (), and HashMap recalculated hash key value; the HashTable when seeking a position corresponding to the hash value of the index, using modulo arithmetic, and HashMap position index when evaluated, with the aND operation, the first and generically herein 0x7FFFFFFF the hash &, and then the length calculation object is to convert a negative hash value is positive;
(. 6) the HashMap removed the HashTable contains in method (comparison is whether the value is equal to) because this method is misleading; two containsKey classes include methods and containsValue;
(. 7) the HashTable are thread-safe, HashMap is a non-thread-safe.

11. The difference between an array and a linked list of
arrays of features:
(1) in the memory array is a contiguous area that is accessed through the array index, the start index from 0;
(2) an array to reserve space before first use account application memory size can be wasted memory space;
(3) low insertion and deletion of data efficiency, data is inserted, this latter must be moved back in the position data memory; data is removed, this latter data must be moved forward;
(4) random high reading efficiency, because the array is continuous, know the memory address of each data can be found directly specified data;
(5) is not conducive to expansion, the need to redefine the definition of a new array when the array is not enough space and copy.
Advantage of the array:
(1) Random Access Strong
(2) Find a speed
disadvantage array:
(1) Low insertion and deletion efficiency, due to the movement of the other element
(2) may be a waste of memory
(3) Memory space requirements high, there must be enough contiguous memory space
(4) the array size is fixed and can not be dynamically extended
application scenarios:
(1) frequent queries, storage space is not required, rarely adding and deleting situation.
List of features:
(1) in the memory may be present anywhere, does not require continuous;
(2) Each data is stored memory address of the next data, to find the next data at this address;
(3) increase the data and it is easy to delete data;
(4) to find data inefficient, because they do not have random accessibility, data access to a location must begin from the first data;
(5) do not specify a size for easy expansion, the size of the list without defining the data be added or deleted.
List of advantages:
(1) insertion and deletion speed
(2) high memory utilization efficiency without wasting memory
(3) size is not fixed, flexible extension
(4) does not require initial capacity
list of disadvantages:
(1) can not be found randomly, from a first traversing must find inefficient
(2) because it contains a large number of pointer field, space large
application scenarios:
small (1) the amount of data that needs to frequently add, delete scenes operations.

12. The understanding of the class loading process
BootStrapClassLoader corresponding to the JRE / lib / rt.jar;
ExtClassLoader corresponding to the JRE / lib / EXT / * jar;.
The AppClassLoader corresponding to all the jar or directory (the default class loader) specified by the Classpath;
parent delegation mechanism :
when a class loader receives a class loading task, loading does not expand immediately, but will load the task entrusted to its parent class loader to perform each layer's class loader are used in the same manner, until entrusted to boot up the topmost class loader. If the parent class loader can not load class entrusted to it, load the task put the class returned to the next level class loader to perform the load.

13. Java in how to use JDBC to create and submit a transaction

Conn = null the java.sql.Connection; 
java.sql.PreparedStatement stmt = null; 
the try { 
    Conn the DriverManager.getConnection = ( "JDBC: Oracle: Thin:, @host: 1521: the SID", "username", "the passwd"); 
    // automatically submits set to false, if set to true, then the database will update the data each time a transaction is identified and automatically submit 
    conn.setAutoCommit (to false); 
    stmt = conn.createStatement (); 
    // the account a reduce the amount of 500 
    stmt.execute ( "Update t_account SET aMOUNT aMOUNT = - 500 WHERE ACCOUNT_ID = 'a'"); 
    // account the amount of increase B 500 
    stmt.execute ( "Update t_account SET aMOUNT aMOUNT + = 500 WHERE = ACCOUNT_ID 'B' "); 
    // commit the transaction 
    conn.commit (); 
} the catch (Exception E) { 
        conn.rollback ();
} finally {
    stmt.close();
    conn.close();
}

 
14. How to achieve multiple inheritance Java
inner classes can implement multiple inheritance, directly on the code:

public class Test {
    private class MyCall extends Call {
        
    }
    private class MySendMessage extends SendMessage {
        
    }
    private MyCall call = new MyCall();
    private MySendMessage sm = new MySendMessage();
    
    public void call(String phoneNumber) {
        call.call(phoneNumber);
    }
    public void send(String phoneNumber) {
        sm.send(phoneNumber);
    }
    
    public static void main(String[] args) {
        Test t = new Test();
        t.call("110");
        t.send("119");
    }
}
class Call {
    public void call(String phoneNumber) {
        System.out.println("call the number: " + phoneNumber);
    }
}
class SendMessage {
    public void send(String phoneNumber) {
        System.out.println("send the number: " + phoneNumber);
    }
}

 
15. String, StringBuilder, StringBuffer Comparative
main difference is that the three classes thread safe speed;
speed: StringBuilder> StringBuffer> String
reasons: StringBuilder and StringBuffer are variable, String is a constant; if String str = "abc"; str + = "de";, str is initialized to abc, after jvm create a new object "abcde", this new object is assigned to str, and the original "abc" will be garbage collection mechanism recovery, so the operation actual String object on a constantly create new objects and old objects recycling process; and the operation of StringBuilder and StringBuffer are directly variable changes, does not include the creation and recovery operations targeting;
String str = "abc" + "de"; / / the role and operation String str = "abcde"; the same, it will be soon,
String str1 = "abc", str2 = "de"; str1 = str1 + str2; // this operation will be very slow;
thread-safe: StringBuilder is not thread-safe, StringBuffer is thread-safe;
string: apply a small amount of string manipulation;
the StringBuilder: suitable for a character in single-threaded The case of the red zone a number of things;
StringBuffer: the case of a large number of suitable multi-threaded operating under the character buffer.

16.


System.out.println (i.ToString ());
System.out.println (Integer.toString (I));
System.out.println (String.valueOf (I));
String converted to Integer:
String = STR " ... ";
Integer I = null;
IF (STR = null!) {
    I = Integer.valueOf (STR);
}
(constructor may be used)

17. a string removing the Java spaces what function
trim: head and tail removed space;
replace: remove all spaces, inclusive, an intermediate; oldchar is replaced newChar;
STR = str.replace ( "", ""); // remove all spaces;
the replaceAll: remove all spaces; parameter regex (regex);
STR = str.replaceAll ( "\\ S *", ""); // replace most blank characters is not limited to the space;
STR = str.replaceAll ( "+", ""); / / remove all spaces;
\ S matches spaces, tabs, any of a blank page break character and the like.

18. The principle of automatic boxing and unboxing
Autoboxing: Integer object when assigned to a value of int, Integer.valueOf method calls, if the value in the range -128 to 127, will be cached in memory; If not within this range, go to a new Integer object.
Automatic unboxing: binary operator acting on the package type will cause unboxing, unboxing essence is to call a method intValue; and == = binary operators with special, and a package type or a base type! expression (i.e., comprising arithmetic) or = == for comparison, will first packaging types unpacking operation, and then after the comparison;! packaging the two types or = == operation, directly address comparison!.

19. The reference value is passed with the principles passed
value transfer: function of receiving a copy of the original value, and the two equal basic types stored in memory, i.e., formal parameters and actual parameters, the method of operation of the back are on the parameter changes, does not affect the value of the actual parameter;
reference transfer: function receives the memory address of the original value, in the process of execution, the same shape and actual parameter content, point to perform the same memory address, method of operation of the reference in It will affect the actual object;
public void swap (x Student, Student Y) {
    Student TEMP = x;
    x = Y;
    Y = TEMP;
}
execution swap methods:
(1) the object a, b are copied to x , y, x, and at this time point to the same object a, b, and y refer to the same object;
(2) the method to complete the swap x, y exchange, a, b and does not change;
(3) the method is finished, x, y no longer use, a, b before still pointing object;
in summary, Java is a parameter passing mode: transfer value.

Comparison with the cover 20. The method of method overloading
Method overloading: at compile time, the compiler is called when the polymorphism, the compiler can choose which type of parameter according to the method;
method of covering (rewritten): occur at run time, is referred to as multi-state operation, since compile compiler does not know and can not know which method to call, JVM runtime code will make the decision;
rewrite the method to follow the "two with a big two small" rule that the same "with two" method name, the same parameter list; "two small" sub-class method returns a value that is the type of the return value should be less than or equal to the type of the parent class method, method declarations subclass thrown exception class class method should throw than the parent class declaration smaller or equivalent; "a big" refers to access a subclass method should be greater than the permissions of the parent class method or equivalent; in particular, it should be noted that the override method, and is covered by either method is a class method, either all instances method, not a class method is an instance method;
method overload only with "the same two different" about: same name, same method name, a different parameter list.

21. Comparison of the abstract class interface
(1) interface is disclosed, public static final of Field, public abstract of Method; An abstract class can have private variables and private methods, there may constructor;
(2) interface is a has-a relationship; abstract class is-a relationship;
(3) a class can inherit one, but a plurality of interfaces may be implemented;
(4) a general application, the topmost layer is the interface, followed by an abstract class, then the implementation class;
( 5) example: Door open and close function having, if we want to add a warning alarm function, the best solution is to design an abstract class Door, open and close methods comprising; redesign an interface method comprising alarm; Door as having open and close methods do not necessarily have the alarm function with alarm function is not necessarily on the Door, open nature of the alarm is not something on the same level; open and close for Door is is-a relationship, for alarm for Door is a has-a relationship.

22. The generic role
Java1.5 introduces a generic, all the collection interfaces are using it. Action:
(1) generic allows us to offer a type of object can hold as a collection, so if you add any other type of element, it will complain at compile time; this avoids ClassCastException at run time, because you will compile-time error information obtained;
(2) such that the generic code is also clean, we do not use the explicit conversion and instanceof operator.

23. What is the iterator (the Iterator)
iterator is a design pattern, it is an object, and can traverse the selected target sequence, and the developer does not need to understand the underlying structure of the sequence;
java.lang.Iterable interfaces, Collection is inherited;
Iterator set and method are defined in the interface list, but is present only ListIterator interface list (or implementation class);
ListIterator have add method, the object may be added to the List, but not Iterator;
ListIterator and Iterator hasNext and next both methods, the sequence may be implemented to traverse back, but there ListIterator hasPrevious and previous methods, may be implemented reverse (forward order) traversal, the Iterator can not;
ListIterator index can locate the current position, may be implemented nextIndex and previousIndex , Iterator does not have this feature;
can be realized delete an object, but ListIterator modify objects can be achieved, set the method can be achieved, Iierator only traversal, can not be modified. 

24. Error Exception in comparison with
Java all the errors packaged as an object whose parent is simply Throwable, Throwable has two subclasses, Error and Exception;
Error is a subclass of Throwable, is used to indicate that a reasonable application (JVM) should not try to catch serious problems ;
Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application (JVM) want to capture;
RuntimeException that might be thrown during the normal operation of the Java virtual machine abnormal superclass without explained in the throws. RuntimeException also called unchecked exception (an unchecked Exception) (as the rest of the Exception checked exceptions), not because of abnormalities is not necessary to check the programmer, because of negligence and abnormalities due to error;
checked exceptions: definition method when you must declare all might throw a checked exception; when you call this method, it must be captured, otherwise it will pass it down.

25. Comparison of member variables and local variables
member variables: the method defined inside the outer, class variables, which are stored in the member variable objects in the heap, the garbage collector is responsible for recycling;
local variables: internal methods or variables defined statement block the formal parameter is a local variable, the data stored in the local variable stack memory. Local variable stack memory disappears with the disappearance of the method, you can not use the access specifier.
Member variables without explicitly initialized; parameter into a local variable, method of local variables, local variables block, in addition to the parameter, local variables must be explicitly initialized.
In the same class, member variables scope is valid over the entire class, a class can not be defined two member variables of the same name, is a class even Field, a Field nor is an example;
a method can not be defined in two with the same name local variables, even when a local variable is the method, a code block is a local variable or parameter does not work;
Java allows local variables and member variables of the same name, if the method in the local variables and member variables of the same name, the local variable overrides the member variables, if you need to reference member variables covered In this method, you can use this (for instance Field) or class name (for class Field) as the caller to restrict access to member variables.

Guess you like

Origin www.cnblogs.com/yuanfei1110111/p/10991596.html