Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Inheritance creates type compatibility. It allows a super class reference to refer to the object of sub class. (Reverse is not true).</p> <p>A super class reference, that refers to object of sub class, can only be used to access the inherited and overridden methods of sub class. The members newly defined in sub class are not accessible using reference of super class.</p> <pre><code>class A { void f1() { //this holds address of object of B System.out.println("A f1"); } void f2() { System.out.println("A f2"); } }//A class B extends A { void f3() { //new method System.out.println("B f3"); } void f2() { //this holds address of object of B System.out.println("B f2 starts"); f3(); //this.f3() System.out.println("B f2 ends "); } } //B class TypeCmptbl { public static void main(String args[]) { A ref; //reference of A ref = new B();//Object of B //ref.inherited() allowed ref.f1(); //ref.overridden() allowed ref.f2(); //ref.newMembersOfChild() not allowed //ref.f3(); }//main } </code></pre> <p>Consider the statement</p> <pre><code> ref.f2(); </code></pre> <p>Here ref is a reference of class A and it has address of object of class B f2() is a overridden method.</p> <p>When compiler detects such a statement then it doesn't bind the function call with any definition. It only validates the call. </p> <p>Binding of such calls is left for the runtime environment. At program runtime system identifies the datatype of the object and binds the function call with the function definition provided by the class of object. This type of binding between the function call and function defination is called as "late binding" or "<strong>runtime binding</strong>" or "<strong>runtime polymorphism</strong>" or "<strong>dynamic method dispatch</strong>".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload