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 8504665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:05:58+00:00 2026-06-11T02:05:58+00:00

public class Graph { private Node node; public void createGraph() { } private class

  • 0
public class Graph {

    private Node node;

    public void createGraph()
    {

    }

    private class Node<K>{
        K data;
        List<Node> adjacent;
        boolean visited; 

        Node()
        {
            adjacent = new ArrayList<Node>();
            visited = false;
        }

        Node(K data)
        {
            this.data = data;
            this.Node();

        }

    }



}

Why is the compiler complaining that I can’t call this.Node() ?

  • 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-11T02:05:59+00:00Added an answer on June 11, 2026 at 2:05 am

    Try:

     Node(K data)
        {
            this();
            this.data = data;
    
        }
    

    The call to the “other” constructor needs to be always first. The call to the other constructors from inside a constructor is always done with this(...) not with Node(...).

    JLS section 8.8.7 specify how the constructor body should look like:

    ConstructorBody: { ExplicitConstructorInvocation(opt)
    BlockStatements(opt)
    }

    where ExplicitConstructorInvocation(opt) is either an alternate constructor or a constructor from the parent class invoked with super(...).

    and JLS section 12.5 specify the object initialization steps when a constructor is called:

    Just before a reference to the newly created object is returned as the result, the indicated constructor is processed to initialize the new object using the following procedure:

    • Assign the arguments for the constructor to newly created parameter variables for this constructor invocation.

    • If this constructor begins with an explicit constructor invocation (§8.8.7.1) of another constructor in the same class (using this), then evaluate the arguments and process that constructor invocation recursively using these same five steps.

    …

    These JLS rules make sure that the parent class constructor is called first and once.

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

Sidebar

Related Questions

public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
I have a Node class: public class Node { private string name; private Point3D
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
public class LinkedList { Object contents; LinkedList next = null; public boolean equals(Object item)
public class HttpPostTask extends AsyncTask<Void, Integer, Void> { TextView txtStatus = (TextView)findViewById(R.id.txtStatus); @Override protected
I have the following object Node : private class Node implements Comparable<Node>(){ private String
I require a tree / directed acyclic graph implementation something like this: public class
I have an Object called Graph. I have list of Vertices in Graph class.
Here is my class: template <class T> class Vertex { private: T data; Vertex<T>*
I'm writing a class in Java to represent a Graph data structure. This is

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.