title: How does a JVM execute the Inheritance tree structure?
body: <pre><code>class Vehicle {
      public int wheels;
      public int lights;
  }
  
  class Car extends Vehicle {
      public int wheels =4;
      public int lights =2;
  
      public void lights_on( int lights) {
          //Code to onlights 
      }
  }
  
  class BMWCar extends Car {
       public int wheels = 4;
       public int lights = 4;
  }
  
  public class TestCar {
      public static void main(String args[]) {
          //Creating a new instance of BMWCAR by calling the default
          // constructor provided by the constructor
  
          bmwCar = new BMWCAR();
          bmwCar.lights_on();
      }
  }
  </code></pre>
  
  <p>In the above example, when I run the <code>TestCar.java</code> file, The JVM's class loader loads the <code>TestCar</code> file into the method area, and it executes the main method. When a <code>bmwCar</code> instance is created, it calls the default constructor of the <code>BMWCar</code> class and executes the super constructor, which is the <code>Car</code> class's default constructor. I would like to know why when the <code>bmwCar.lights_on();</code> method is called the JVM looks for the <code>lights_on</code> method and in the <code>bmwCar</code> object it initalizes the value of instance variables wheels and lights i.e. <code>4</code> and <code>4</code>.  </p>
  
  <p>When the <code>lights_on();</code> method is executed in the <code>Car</code> class, does the JVM reintialize the value? How is the reference passed from <code>bmwCar.lights_on</code> to the <code>Car</code> class <code>lights_on</code> method? I am looking for a detailed answer about the workflow.</p>