I am learning Java from Udemy, complete java masterclass. For challenge "Abstract class challenge" narrator states says I should create 2 references 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 references a reference and not a value?
They both start with protected, then we have type, then we have variable name. The only difference is that reference has assigned value of null.
But if were to make for example:
private int myNumber = 10;
Above is not called a reference, it is called a variable myNumber of type int with value 10.
It is not a value in the context of the Java language. In the context of the Java language, all three fields are references.
I see it as a value in the context of a linked list.
In context of a linked list, an object of type Object
is going to be an actual value that is stored in the list. And ListItem
is a reference to another list item because that is how linked lists are connected.
Seems like the course material does not make it as clear as it should.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With