0
import java.util.*;

public class List
{
    public static INode head;
    public List()
    {
        head = new INode(8);

    }
    public static void main (String[] args)
    {
        INode a = new INode(8);
        int data = a.getValue();
        System.out.println(data);
        System.out.println(head.getValue());
    }


}

And my Node class:

public class INode
    {
        private int value;
        private INode right, down;
        private int row, col;

        public INode(int value)
        {
            this.value = value;
        }

        public int getValue() 
        {
            return value;
        }

        public void setValue(int value) 
        {
            this.value = value;
        }

        public INode getRight() 
        {
            return right;
        }

        public void setRight(INode right) 
        {
            this.right = right;
        }

        public INode getDown() 
        {
            return down;
        }

        public void setDown(INode down)
        {
            this.down = down;
        }

        public int getRow() 
        {
            return row;
        }

        public void setRow(int row) 
        {
            this.row = row;
        }

        public int getCol() 
        {
            return col;
        }

        public void setCol(int col) 
        {
            this.col = col;
        }


    }

Yea, head give me null, while a give me 8... can someone explains it to me?

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by jalpesh_007
1

because you haven't called the constructor of your class, which means that your head list never gets instantiated either.

0

you haven't make object(instantiated) your class List, so your head variable is not initialized.

make object of that class with constructor.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.