This is because your Node
inner class is non-static. Non-static classes in Java have an implicit reference to their enclosing class, so they must be instantiated by an instance method of the outer class. Instantiating it like this
Queue.Node newNode=new Queue.Node();
is not valid, even though the Node
class is public
.
Declare it with the static
keyword to fix this compile issue: the class can be logically made static
, because its methods do not require knowledge of the enclosing Queue
class.