File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes super class constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "super class constructor" Watch "super class constructor" New topic
Author

super class constructor

Mitch Krah
Ranch Hand

Joined: Sep 06, 2004
Posts: 41
I have the following code:

class Snack extends VendingMachinePoly {
private double cost;
private int calories;

// Parameterized constructor
Snack(double c, int cal) {
super(50, 50.0, c);
cost = c;
calories = cal;

When I compile the program I get an error that states:

"Snack.java": cannot resolve symbol: constructor VendingMachinePoly (int,double,double)in class chapter9.VendingMachinePoly at line 26, column 5

However, the following is what I have in VendingMachinPoly for the constructor:

// non-Default Constructor, n is the # of items the machine starts with
VendingMachinePoly(int n, double d, double cost) {
itemCount = n;
moneyCredit = 0;
totalMoney = d;
itemCost = cost;

I have tried many combinations of "int, double, double" to pass to the constructor of super (VendingMachinePoly), but nothing appears to help. Can anyone help explain what the compiler is trying to tell me???

Thank you,
Mitch
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What access qualifier do you have on your superclass constructor? Are these two classes in the same package?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Mitch Krah
Ranch Hand

Joined: Sep 06, 2004
Posts: 41
I used public and none for the qualifier (tried both). Neither worked. Yes they are both in the same package (chapter9).

Any thoughts?

Thank you,
Mitch
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You haven't accidentally given the superclass constructor a return type, making it into a normal function that just looks like a constructor, have you?


[Jess in Action][AskingGoodQuestions]
Mitch Krah
Ranch Hand

Joined: Sep 06, 2004
Posts: 41
No return on the constructor. But, that was a good check.
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
Do you have another version of the class file 'VendingMachinePoly' (maybe an older one) somewhere in the classpath? Maybe that version is getting picked up first.
Mitch Krah
Ranch Hand

Joined: Sep 06, 2004
Posts: 41
I did not believe there was more than one VendingMachinePoly. I could not find more than one (searched the entire directory with windows explorer). Again, another really good ckeck. I would not have thought about that at all.

Thank you,
Mitch
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I compiled it OK so the error is not in the code you posted.

I think maybe you should post a cut and paste of the full code. Please use the UBB button "CODE" to preserve indentation.


Mike Gershman
SCJP 1.4, SCWCD in process
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
If this were my bug, my next step would be to create a no-arg VendingMachinePoly constructor and see if super() worked. That would tell me where the problem was.

If super() worked, I would add one parameter at a time to see which one was causing the error.

If super() failed, I would put both classes in one compilation unit (only one class can be public) to eliminate classpath isues.
Good luck!

Please reread this post. I fixed some errors.
[ November 21, 2004: Message edited by: Mike Gershman ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: super class constructor