Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
constructor from diffrent class
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="rossum, post: 2990928"] 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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
constructor from diffrent class
Top