Well first of all, in Java all interfaces are abstract. Whether you use the keyword "abstract" or not. They are abstract because you define no implementation and any object that uses the interface is obligated to override all methods of the interface.
Secondly, this error about non-static methods is because main itself is static. Meaning that you don't need to create an instance of main in order to use it. Saying that, anything that is called by main directly must also be static since again, you don't need an instance of main, so it makes no sense to have instances inside something which itself is not an instance.
Thirdly, the main reason you are getting the error is because of how you are using your Mylist class. Remember that Mylist still needs to be an instance to use its methods. The polymorphism comes in because your MyStack or MyQueue can be instances of Mylist.
So you the object passed into your ShowData could be a MyStack or MyQueue object tucked away in a MyList. That is the polymorphism part. So in that function you need to change MyList to simply "obj" and use the object as an instance of Mylist... even if they are really Mystack or MyQueue objects.
CODE
public static void showData(MyList obj)
{
// obj could be either a stack or queue, but we use it as its base
// class MyList. The interface allows us to use isEmpty despite the
// class' true type.
while (!obj.isEmpty())
{
int number = obj.remove();
System.out.println(number);
}
}
Now making this change will allow your program to compile. However you have another error you have not discovered yet. Your remove method of the MyStack class runs out of bounds on the array. So check that part out and make sure that you are not trying to access the array when value of "top" is less than 0.
In your remove method you should check the top value before attempting a remove. Since you call removeData which decrements the index. oh and size should never equal -1... because it started at zero. Top should be -1 when empty and size would be 0.
So take a look at your incrementing/decrementing and I am sure you will see what is going on.
Good luck!
"At DIC we be polymorphism master ninjas!"
This post has been edited by Martyr2: 2 Feb, 2008 - 08:32 AM