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;
}
}
I can get value of a = 8 but for head, even though I use constructor to set up, still give me value = null… dont know why.
And the driver is:
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());
}
}
Please help me a hand guys. Dont understand why when I use a constructor, I cant assign the value to the node, yet when I create an instance, i can…
Thank guys, love you folks! Great help!
You do not instantiate the class
List. Change your code toAnd modify your main method:
Another valid alternative would be to change just one line:
I recommend to look at the difference between class (static) and instance variables, e.g. in the Java Tutorials (extract follows):