Java Inheritance

I recently went through the concept of inheritance.

As we all know, in inheritance, objects superclassare created / initialized before objects subclass. Therefore, if we create an object subclass, it will contain all the information about the superclass.

But I was stuck at some point.

Are superclass and subclass methods used in a separate call stack? If so, is there specific reasonfor the same? If this is not the case, why aren't they showing up on the same call stack?

eg.

// Superclass
class A {
    void play1( ) {
        // ....
    }
}

// Subclass
class B extends A {  
    void play2( ) {  
        //.....   
    }
}

Then run if the above method, ie 2 play1( )and play2( )in a separate call stack?

Thank.

+5
source share
2 answers

. . , - , . - .

class A {
  void play1() {
    //...
  }
  void play2() {
    //....
  }
}
class B extends A {
  void play1() {
    //...
  }
}
B b = new B();
b.play1(); // 'first' call
b.play2(); // 'second' call

A.play2() " ". B.play1() " ". A.play1() .

+2

, , playX .

, , , . , , , (, , ), , , -, .

+2

All Articles