Hiya folks!
This is a question about constructors in classes that are extended. I just want to be sure, that I've understood the subject.
During this post I will primarily be using two classes: SuperClass and SubClass (which extends SuperClass). Both classes are placed in a file called SubclassConstructor.
1. When I call SubClass s = new SubClass() the constructor of Superclass will be called first and at last SubClass' constructor is called.
For the fun of it I make this example:
The output is:
superclass constructor!
Sub class' constructor!
This is SubClass2
But! - and here comes my question:
If I place the following constructor in SuperClass: public SuperClass(
String s) and try to initialize SubClass from the main method (as in the following example) with this line: SubClass sc = new SubClass("test"); then I get a compiler error.. why ? can anyone help here?
Is it because you can't inherit the constructor ? (I dont think so - cause the constructor of SuperClass was called in the 1. example).
Thanks in advance
/Svend Rost
ps. I edited a few typos in the text.
[ December 02, 2002: Message edited by: Svend Rost ]