Hello Folks, I was just playing around with one of the codes given in Khalid Mughal's book "A programmer's guide to Java Certification". I modified the original code slightly(Shown Below)which the compiler doesn't apparently seem to like. It'd be great if anyone could tell me why.
The error message given by the compiler is... imp.java:59: cannot resolve symbol symbol : constructor PrintableCharStack () location: class PrintableCharStack public class imp extends PrintableCharStack{ ^
Thanks in Advance Shyam (Edited to do some formatting on the code)
[This message has been edited by Shyamsundar Gururaj (edited August 14, 2001).]
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
I got it myself.
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
I'm still not totally clear about why but it seems that you must include a constructor in CharStack and PrintableCharStack that takes zero arguments! can someone please clearify this!
Hi Mathias, class CharStack has one constructor that takes int as argument so you have to specify one no-arg constructor explicity. class PrintableCharStack also has one constructor with int argument, it explicity calls the super(int) constructor so there is no problem.
class imp (extending printablecharstack), has no constructor at all, so default no-arg constructor is available for imp. This default constructor will call super(), so you should specify no-arg constrctor in the super class.
Hope this helps, Vanitha.
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
vanitha, Actually the class imp does not extend class PrintableCharStack. The code that I had posted originally did not compile with the statement "public class imp extends PrintableCharStack" (You can see the error message in my first post). The program compiled only after I changed that part of the code to "public class imp". Thanks Shyam (Edited to correct typos) [This message has been edited by Shyamsundar Gururaj (edited August 11, 2001).]
Vanitha Sugumaran
Ranch Hand
Joined: Apr 11, 2001
Posts: 356
posted
0
Hi Shyam, I explained the code you posted earlier. If the class imp extends PrintCharStack you should have no-arg constructor in the super class. Otherwise compiler error occurs. That's what you got. If imp doesn't extend then there is no problem. Vanitha.
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
True...True...But correct me if I am wrong, Vanitha. The super() is used in the subclass to call the constructor in the immediate superclass. If this is the case, then if I say public class imp extends PrintableCharStack, does it mean that the constructor of the CharStack class gets invoked through the PrintableCharStack class's constructor? Apart from this, what modifications would you do to make the code pasted in my first post to compile and run flawlessly? Regards, Shyam
[This message has been edited by Shyamsundar Gururaj (edited August 11, 2001).]