On Sun, 29 Jul 2007 20:01:27 +0200, "Thomas" <arabel9@o2.pl> wrote:
As above I have two classes : abstract Stack and class Function, with
Function holding one instance of Stack. Now, when calling constructor
and Function.java are in project.
pseudocode :
abstract Function{
Stack S;
Function(){
S = Stack();
}
}
When you call any constructor, you need the "new" construction:
S = new Stack();
This will not compile in your particular case because you have
declared your Stack class to be abstract. Abstract classes cannot be
instantiated, and the compiler will tell you so.
One way to initialise the stack member variable in Function is to
initialise it from a constructor parameter:
public Function(Stack ss) {
S = ss;
}
This will compile.
Inside your program you could derive a non-abstract class from your
abstract Stack and you can pass an instance of that derived class into
your Function constructor:
class ConcreteStack extends Stack { ... }
ConcreteStack myCStack = new ConcreteStack();
Function myFunction = new Function(myCStack);
rossum