Forums Register Login

constructor

+Pie Number of slices to send: Send
please explain the output

i was expecting the output as
a=10
b=16

but output is
b = 0
b = 16

actualy subclass constructor should call super (base class constructor) but thats is not happening here..please explain

+Pie Number of slices to send: Send
I think this is what you were trying to do...



The function call is over ridden, so the super constructor calls the derived class call() function. At this point of time b is not initialized with 16 so it prints 0. I changed the function name from call to call_one in the base class.
+Pie Number of slices to send: Send
just for your info,
if you would make call() in bc private, then the result is what you expect..

Because private methods/attributes are not inherited, so no way for polymorphism..

regards,
Flom
+Pie Number of slices to send: Send
when the base class contructor calls the method call() its actually this.call() (am i right?) so it should invoke the base class call method. why the call method from subclass is called?

please explain.
A tiny monkey bit me and I got tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 663 times.
Similar Threads
doubt
Q on Method Invocation !!
Which method is called????
Constructor call
In Consturctor, calling Static method doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:05:36.