R. Laheri February 2016

how to call the constructor of the inner class node in Static main Function

package practice;
class LinkedList
    Node head;  // head of list

    /* Node Class */
    class Node
        int data;
        Node next;

        // Constructor to create a new node
        Node(int d) {data = d; next = null; }
    public static void main(String args[]){
        LinkedList lkd=new LinkedList().new Node();


Alexandermeyeer February 2016

It seems that your constructor is taking one and only one parameter. Unless you override with a constructor that takes no parameters, try:

LinkedList.Node lkd = new LinkedList().new Node(**int d here**);

Post Status

Asked in February 2016
Viewed 1,283 times
Voted 14
Answered 1 times


Leave an answer