| Author |
constructor
|
swapnil paranjape
Ranch Hand
Joined: May 15, 2005
Posts: 125
|
|
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
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
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.
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Flom Xanther
Ranch Hand
Joined: May 26, 2006
Posts: 44
|
|
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
|
 |
swapnil paranjape
Ranch Hand
Joined: May 15, 2005
Posts: 125
|
|
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.
|
 |
 |
|
|
subject: constructor
|
|
|