Suppose I have a Node type.
public class Node{
private Node next;
private int data;
// other methods including constructor and setting next reference.
}
Or using null for uninitialized value like below:
public class Node{
private Node next = null;
private int data;
}
public class Node{
private Node next; //initialized to null
private int data; //initialized to 0
// other methods including constructor and setting next reference.
}
Here next and data are instance variable and unlike local variables they are assigned default values. So next which is an Object will be assigned null value where as data which is an int will be initialized to 0.
So your each Node instance will have data initialized to 0 and next Node set to null. If you want some specific initializations you can do so in the constructor or use corresponding getter/setter methods.
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