Forums Register Login

doubt in constructor...

+Pie Number of slices to send: Send
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?

+Pie Number of slices to send: Send
compiler calls super() inside the Test2l() constructor implicitly. so,it calls Base() which is not there
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Yes you are right..
+Pie Number of slices to send: Send
compiler look for default constructor of base class because you used this code .

Test2l()
{
}


remove above line and it will compile properly.
+Pie Number of slices to send: Send
"vinay ds", please check your private messages for an important administrative matter.
+Pie Number of slices to send: Send
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.
You can't have everything. Where would you put it?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 774 times.
Similar Threads
Constructors
Can some one explain me the answer for this
Default constructor !!!!
A question on constructor
doubt regarding constructors
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:43:09.