public class Queue {
public class ArrayQueue
{
Object store[];
int front,rear;
static final int MAX = 100;
public ArrayQueue()
{
store = new Object[MAX];
front = rear = 0;
}
public void EnQueue(Object o)
{
if((rear +1)%MAX!=front)
{
store [rear] = o;
rear = (rear + 1) % MAX;
}
}
public Object dequeue() throws Exception
{
if( empty())
{
throw new Exception();
}
else
{
Object data = store[front];
store [front] = null;
front = (front+1)%MAX;
return data;
}
}
}
public static void main (String args)
{
main();
}
public static void main()
{
String choice;
Scanner input = new Scanner(System.in);
System.out.println("A.EnQueue");
System.out.println("B.DeQueue");
System.out.println("C.Print");
System.out.println("D.MakeNull");
System.out.println("E.Empty");
System.out.println("F.Full");
System.out.println("G.Exit");
choice = input.nextLine();
switch(choice){
case "A":
System.out.println("Enter a character");
char x;
x= input.next().charAt(0);
// ArrayQueue.EnQueue(x);
System.out.println(x+"was added to the queue");
}
}
}
}
我遇到了静态问题,实际上什么是静态方法,第 76 行是否出现错误,即“ArrayQueue.EnQueue(x);” 如果将 EnQueue 函数设为静态,也会出现错误,这是为什么呢?我该如何解决这个错误。错误是非静态方法 Enqueue (Object) 无法从静态上下文中引用