I am implementing iterator on a class and I keep getting the error for line 1 of the second part. It says that the return type is incompatible with iterator(). I know it has to do with the syntax of what I'm using since I'm new to coding.
import java.util.Random;
import java.util.NoSuchElementException;
public class Stack<Item> implements Iterable{
private Item[] stack;
private int size;
private int N;
public Stack(){
stack = (Item[]) new Object[2];
size = 0;
N = 0;
}
public StackIterator<Item> iterator(){
return new StackIterator<Item>();
}
public class StackIterator<Item> implements Iterator<Item>{