#Dynamic Binding :- It is also called 'Late Binding' . The compiler is not resolve the method call at the compile time. Ex-> Method override calling from the object
Created
February 21, 2021 09:08
-
-
Save kshitijvarshne1/bbd6efb73d7169649b517f322e7d54a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 21-Feb-21 | |
* Time: 2:18 PM | |
* File: DynamicBinding.java | |
*/ | |
package feb21_21.DB; | |
public class DynamicBinding { | |
public static void main(String[] args) { | |
Airplane myAirplane= new Jet(); | |
//object reference is from the child class | |
// the reference variable if from the parent class | |
// We can store the reference value of the object of the child class, | |
// inside the reference variable of its parent class, but not vice versa | |
// Now the compiler has to be confused | |
myAirplane.display(); | |
// compiler simply go to Jet class if method is available the simply run otherwise go to parent class | |
// This is confusing for compiler | |
// This problem is resolving at the runtime | |
} | |
static class Airplane{ | |
public void display(){ | |
System.out.println("Airplane class"); | |
} | |
} | |
static class Jet extends Airplane{ | |
@Override | |
public void display(){ | |
System.out.println("Jet class"); | |
} | |
public void displayFuelStatus(){ | |
System.out.println("Tank is full"); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment