Difference between value and reference in Java exercise?

I am learning Java from Udemy, a complete java master class . For the "Abstract class problems" task, storytellers say that I have to create 2 links and 1 value in an abstract class.

In the solution, this is the result:

public abstract class ListItem {
    // references
    protected ListItem rightLink = null;
    protected ListItem leftLink = null;

    // value
    protected Object object;
}

What makes links a link, not a value?

Both of them start with protected, then we have a type, then we have a variable name. The only difference is that the link is null.

But if done, for example:

private int myNumber = 10;

Above is not called a link, it is called an int variable myNumber with a value of 10.

+4
source share
4 answers

This is not a meaning in the context of the Java language. In the context of the Java language, all three fields are links.

. Object , . ListItem , .

, , .

+12

"" "" , Java.

, , . .

, " " , , , :

  • ,
  • node,
  • ,
  • - -

.. "", " "; "", , . , , .

+3

, , LinkedList. ListItem Item, :

protected ListItem rightLink = null;
protected ListItem leftLink = null;

, :

protected Object object;

, Object.

+2

Visual explanation

I think you will visit the "Pass by value" or "Link" link , you can find a solution

-1
source

Source: https://habr.com/ru/post/1691033/


All Articles