如何在Static main Function中调用内部类节点的构造函数

时间:2016-02-08 18:34:41

标签: java

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();
    }
}

1 个答案:

答案 0 :(得分:0)

您的构造函数似乎只接受一个参数。除非使用不带参数的构造函数覆盖,否则请尝试:

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