inotgo.com


Tool version compatibility problem
The concept of reference , If the type of a variable is Class type , Not the basic type , Then this variable is also called a reference .
Correct

This video is interpretive , So I hope you have read the content of this knowledge point , And after writing the corresponding code , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning



9 branch 46 second
This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers



Step 1 : Reference and point to   
Step 2 : Multiple references , An object   
Step 3 : A reference , Multiple objects   
Step 4 : practice - quote   
Step 5 : answer - quote   


new Hero();

On behalf of establish I got a Hero Object
But it just creates an object , There is no way to access it
To access this object , Can use quote come On behalf of This object

Hero h = new Hero();

h This variable is Hero type , Also known as quotation
= Means h This reference On behalf of The object created on the right
On behalf of ” In object-oriented , Also called “ Point to
 Reference and point to
public class Hero { String name; // full name float hp; // Blood volume float armor; // Armor int moveSpeed; // Moving speed public static void main(String[] args) { // Create an object new Hero(); // Use a reference to point to this object Hero h = new Hero(); } }
public class Hero {
     
    String name; // full name 
     
    float hp; // Blood volume 
     
    float armor; // Armor 
     
    int moveSpeed; // Moving speed 
     
    public static void main(String[] args) {
    	// Create an object 
        new Hero();
        
        // Use a reference to point to this object 
        Hero h = new Hero();
        
    }   
     
}
Step 2 :

Multiple references , An object

edit top fracture
There are multiple references , But there is only one object .
In this case , All references point to the same object .
Objects are like " house property ", References are like " property ownership certificate "
There can be more than one copy of the house property certificate , But the real " house property " There's only one place
 Multiple references , An object
public class Hero { String name; // full name float hp; // Blood volume float armor; // Armor int moveSpeed; // Moving speed public static void main(String[] args) { // Use a reference to point to this object Hero h1 = new Hero(); Hero h2 = h1; //h2 Point to h1 The object pointed to Hero h3 = h1; Hero h4 = h1; Hero h5 = h4; //h1,h2,h3,h4,h5 Five references , All point to the same object } }
Step 3 :

A reference , Multiple objects

edit top fracture
The first 8 that 's ok , quote garen Point to the newly created object ( Object 1)
The first 9 that 's ok , Same reference garen Point to the newly created object ( Object 2)
This time , Object 1, There is no reference to
let me put it another way , There is no means to control and access the object , Then the object becomes meaningless .
 A reference , Multiple objects
package charactor; public class Hero { public String name; protected float hp; public static void main(String[] args) { Hero garen = new Hero(); garen = new Hero(); } }
package charactor;

public class Hero {
	public String name; 
	protected float hp; 

	public static void main(String[] args) {
	       Hero garen =  new Hero();
	       garen =  new Hero();
	}
}
Step 4 :

practice - quote

edit top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
Such as code , problem :
h4 The object and h2 The object pointed to , Whether it is the same object ?
package charactor; public class Hero { public String name; protected float hp; public static void main(String[] args) { Hero h1 = new Hero(); Hero h2 = new Hero(); Hero h3; Hero h4; h3 = h1; h4 = h3; } }
package charactor;
 
public class Hero {
    public String name; 
    protected float hp; 
 
    public static void main(String[] args) {
           Hero h1 =  new Hero();
           Hero h2 =  new Hero();
           Hero h3;
           Hero h4;
           h3 = h1;
           h4 = h3;
    }
}
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

1 branch 43 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers


If shown ,h4 Point to h3, Finally, it indirectly points to Object 1
and h2 It points to Object 2, So h4 and h2 no Point to the same object
 answer - quote


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2021-07-27 Watfa
Floating clouds have water

ClassDX h1 = new ClassDX(); ClassDX h2 = new ClassDX(); ClassDX h3; ClassDX h4; h3 = h1; h4 = h3; Not yet h2,h1 Points to a new object , then h4\h3\h1 Point to the centipede , It's all interesting , Point to Xinjian's object as a reference . Look again h2, It also points to a new object , Here , Object names are all the same , But he built that thing , It's two objects with the first new one , So h2 Obviously, and h134 Is not pointing to an object . If it's still unclear , You can see the steps 3, It's very clear that , New object 1,2




3 One answer

phm228
Answer time :2021-10-20
Not an object .

szy000178519
Answer time :2021-10-08
Created two objects ,h1,h3,h4 Point to the object 1,h2 Point to the object 2

Floating clouds have water
Answer time :2021-07-27
So h1,h3,h4 It points to the same object 1,h2 It points to the object 2



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-09-25 Draw your own diagram
Learn every day Java Ah




Look online , Learn to draw pictures
 Loading
 
               
 
               


10 One answer

wxw727123
Answer time :2021-10-14
public class Hero { public String name; protected float hp; public static void main(String[] args) { Hero h1 = new Hero(); Hero h2 = new Hero(); Hero h3; Hero h4; h3 = h1; h4 = h3; System.out.println("h1:"+h1); System.out.println("h2:"+h2); System.out.println("h3:"+h3); System.out.println("h4:"+h4); System.out.println("h1,h3,h4 Point to the same object ,h2 Point to an object alone "); } }

zh311184
Answer time :2021-07-07
Video from that place ?stack How to get out of the stack without opening your mouth

1922649889
Answer time :2021-06-17
 no ,

wxtlove1314
Answer time :2021-06-02
Hero h1 = new Hero(); Hero h2 = new Hero(); Hero h3; Hero h4; h3 = h1; h4 = h3;
 The first two lines indicate that two numbers with addresses have been created ; Its address is different 
 The third and fourth lines define two variables 
 The fifth line puts h1 Your address to h3, At this point h3 Point to the place and h1 Same 
 The sixth line puts h3 Address of ( That is h1 Address of ), At this point h4,h3,h1 Same address 
h2 Your address is different ,h1,h2 It's all stored inside 

Unlimited monthly
Answer time :2021-05-02
h4 Point to h1 of 
h2  Point to h2

Big Data Engineer
Answer time :2021-04-05
In this case , Drawing is really easy to understand

wwzjavaer
Answer time :2021-03-18
rain
Answer time :2021-03-17
System.out.println(h1); System.out.println(h2); System.out.println(h3); System.out.println(h4);

Jieyu
Answer time :2021-03-13
babab
Answer time :2020-10-19
public static void main(String[] args) { Hero h1 = new Hero(); Hero h2 = new Hero(); Hero h3; Hero h4; h3 = h1; h4 = h3; System.out.println("h4 Your address is :" + h4); System.out.println("h2 Your address is :" + h2); }



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2020-06-20 Not the same object, not the same value
2020-06-08 Different directions
2020-03-08 In the print name Who do you mean ?


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 31 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Basics - Classes and objects - quote Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot