Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:02:35+00:00 2026-06-13T14:02:35+00:00

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

  • 0
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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:02:37+00:00Added an answer on June 13, 2026 at 2:02 pm

    You do not instantiate the class List. Change your code to

    public INode head; // remove static
    public List() {
        head = new INode(8);
    }
    

    And modify your main method:

    public static void main (String[] args) {
        INode a = new INode(8);
        int data = a.getValue();
        System.out.println(data);
    
        List l = new List(); // create new List instance
        System.out.println(l.head.getValue()); // get the head from List instance
    }
    

    Another valid alternative would be to change just one line:

    public static INode head = new INode(8); // create instance during class initialization
    

    I recommend to look at the difference between class (static) and instance variables, e.g. in the Java Tutorials (extract follows):

    • Instance Variables (Non-Static Fields) Technically speaking, objects store their individual states in “non-static fields”, that is,
      fields declared without the static keyword. Non-static fields are also
      known as instance variables because their values are unique to each
      instance of a class (to each object, in other words); the currentSpeed
      of one bicycle is independent from the currentSpeed of another.

    • Class Variables (Static Fields) A class variable is any field declared with the static modifier; this tells the compiler that there
      is exactly one copy of this variable in existence, regardless of how
      many times the class has been instantiated. A field defining the
      number of gears for a particular kind of bicycle could be marked as
      static since conceptually the same number of gears will apply to all
      instances. The code static int numGears = 6; would create such a
      static field. Additionally, the keyword final could be added to
      indicate that the number of gears will never change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class DoubleMatrix { private double[][] doubMatrix; public DoubleMatrix(int row, int col) { if(row
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class Employee { public static void main(String[] args) { int j=3; staples[] stemp
public class ParserGUI extends javax.swing.JFrame { public ParserGUI() { initComponents(); } private void initComponents()
public class MyClass { public int Age; public int ID; } public void MyMethod()
public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x);
Why doesnt this work? public class ClassOptions {} public interface Inode { ClassOptions Options
Have Controller: public class MyController : Controller { [HttpGet] public ActionResult MyAction(int iMode, string
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.