0

I am implementing a sparse matrix based on the Stack class, and I'm getting the following error:

Sparse.java:6: Sparse is not abstract and does not override abstract method pop() in Stack
public class Sparse implements Stack {

Here is the code snippet in question:

public class Sparse implements Stack {

    static int matrix[][] = new int[6][6];

    public static int[][] Random() {
        Random rand = new Random(seed);
        rand.nextInt(100);
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                matrix[i][j] = rand.nextInt(100);
            }
            return matrix;
        }
    }
}

Any and all help would be appreciated. Thank you.

Perception
  • 79,279
  • 19
  • 185
  • 195
a.ymous
  • 139
  • 11

3 Answers3

4

It means the interface Stack has a method pop(). You must implement the method pop() or it won't compile.

If you must test your code quick and implement the method later, you may want to

public int pop() { // Refer to your Stack interface for signature - they must match.
    throw new UnsupportedOperationException("not implemented");
}
luiges90
  • 4,493
  • 2
  • 28
  • 43
3

A class inheriting Abstract class must override every method in it. (must give definition to it). If not even the child class (sparse) should also be abstract.

But if your class Sparse is Abstract you cannot create object.(but you can create reference variable).

So its better to add

public int pop() { // Refer to your Stack class for signature - they must match.
    throw new UnsupportedOperationException("not implemented");
}

as mentioned by @luiges90

krishna
  • 3,148
  • 5
  • 19
  • 24
1

Seems like you are not much aware about abstract classes and interfaces. Please go through the following links. The will help you. You can always google for more info. :-)

[1] http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html [2] When to use interfaces or abstract classes? When to use both?

Community
  • 1
  • 1
Bikash Rath
  • 159
  • 1
  • 7