Recently I went through the legacy concept
As we all know, the legacy In, the superclass
objects are created before the subclass
objects, so if we create an object of subclass
, then it will include all super class information
But I got stuck at one point.
Do different call-stacks contain superclass and sub-class methods? If so, is there any such specific reason
? If not, why do not they appear on the same call-stack?
Example
// Superclass class A {void play1 () {//. ...}} // The subclass is expanded to class B. A {zero play2 ()} {//}}
Then the above 2 methods i.e. Play1 ()
and play2 ()
appear on a different call stack?
Thank you.
There is no connection between call stack and inheritance. Not really often. If a superclass method is overridden in a child then it is the child's method that is called - Super class method is not executed at all, unless the child is clearly in the code to do so Do not be. Superclass method will not appear at all in the call stack - unless it is explicitly said by the hair method.
class A {void play1 () {// ...} void play2 () {// ....}} Extension of class B A {void play1 () {// ...}} bb = new b (); B.play1 (); // 'first' call b.play2 (); // 'second' call
A.P. 2 () appears only on the call stack during "second call". BP 1 () appears only on the call stack during the "first call" appell 1 () is never seen on the call stack and is never executed.
Comments
Post a Comment