Originally posted by: Semidevil
public class MyStack extends Vector {
public MyStack(s1)
s1= new MyStack
}
is this the right format to create a new stack s1??
I'm a little confused by what you're trying to do in your code. You're defining a new class called MyStack, which you're extending from Vector (I don't agree with this inheritance, but that's okay). Then you have a constructor declared in the line:
public MyStack(s1)
The constructor takes one parameter for which you did not supply a data type. You are missing { } around the body of your constructor. In your constructor, you try to assign a new instance of MyStack to s1 (which is also done incorrectly -- you need parentheses after "new MyStack"). This is in the process of trying to create an initial instance of MyStack.
Let's say you got rid of the syntactical errors, you would be left with a MyStack class that has a constructor that looks like this:
public MyStack(MyStack s1) {
s1 = new MyStack();
}
I'm not sure what use that constructor is. You could use it like this, I suppose:
MyStack v1, v2;
v1 = new MyStack(v2);
And both v1 and v2 would be assigned its own instance of MyStack? I'm not even sure that works, but that's my interpretation of the code.
Your original question was: "is this the right format to create a new stack s1??"
Assuming you correctly defined a class called MyStack elsewhere, then to create a new stack and assign it to a variable s1, I would just do this:
MyStack s1 = new MyStack();
<edit>grammatical error</edit>