I want to know about how late binding works in java.
For example,
public enum Note{
MIDDLE_C,C_SHARP,B_FLAT;
}
class Instrument{
public void play(Note n){
System.out.println("Instrument.play()");
}
}
class Wind extends Instrument{
public void play(Note n){
System.out.println("Wind.play()");
}
}
public class Music{
public static void main(String[] args){
Instrument flute = new Wind();
flute.play(Note.MIDDLE_C);
}
}
In this code, flute is the type 'Instrument' but it can store the type 'Wind', because 'Wind' is the subclass of 'Instrument'.
I thought when we store the object type of 'Wind' to the type of 'Instrument', it only stores the information of 'Instrument', abandoning the information of 'Wind'.
But when we use the method of the object, the late binding will be done so the result will be "Wind.play()".
It is certain that flute is type 'Instrument', but I want to know how JVM regards flute as type 'Wind' so it calls method of 'Wind'.
Does type 'Instrument' flute stores more than just the information of 'Instrument'? Or is there other mechanism of late binding? if so, how?