| Author |
doubt in constructor...
|
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
SOURCE:www.javabeat.net It is giving compilation error as can not find symbol Base() In Base class�.. Here I am calling long parameterized constructor in Test2l class only.. But why this error? Can anyone explain me?
|
SCJP5 and SCWCD1.5
Think Twice Act Wise...
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
compiler calls super() inside the Test2l() constructor implicitly. so,it calls Base() which is not there
|
 |
Aditya Keyal
Ranch Hand
Joined: Dec 01, 2008
Posts: 71
|
|
In any derived class if you have a constructor it MUST explicitly call some constructor of the parent class. If you do not specify then it looks for the default constructor of the Base class. In your case the default constructor of the Test2 class does not explicitly call the parameterized constructor of the Base class. Thus the compiler searches for the default which it cannot find and thus the error. Try removing the default constructor or alternatively calling the parameterized constructor from the default. It will work
|
- Aditya Webservices Blog
|
 |
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
but here it is invoking parameterized constructor in Test2l i.e Test2l(long) by using new Test2l(2); why should it go for default constructor in Test2l?
|
 |
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
the compiler add super(); implicitly so it search for default constructor in Base class which is not available thats why it is showing error.. it doesnot matter which constructor we are invoking we must satisfy compile rules... am i right?
|
 |
James Tharakan
Ranch Hand
Joined: Aug 29, 2008
Posts: 580
|
|
Yes you are right..
|
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
|
 |
Vinay Dinakar
Greenhorn
Joined: Dec 30, 2008
Posts: 17
|
|
compiler look for default constructor of base class because you used this code . Test2l() { } remove above line and it will compile properly.
|
Thanks,
~ Vinay Ds
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
|
"vinay ds", please check your private messages for an important administrative matter.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Punit Singh
Ranch Hand
Joined: Oct 16, 2008
Posts: 952
|
|
If you do not call explicitly super(...) from your constructor, then only compiler will add super(). for your code compiler is adding super() in second constructor.
|
SCJP 6
|
 |
 |
|
|
subject: doubt in constructor...
|
|
|