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();
}
}
In the Above example when i run the TestCar.java file , The JVM's class loader loads the TestCar file on to the Method Area .and It executes the main Method ,When bmwCar instance is created it calls the default Constructor of the BMWCar class and executes the Super Constructor that is Car Class default constructor . I would like to know when the bmwCar.lights_on(); method is called the JVM looks for the lights_on method and in bmwCar Object it initalizes the the value of instance variables wheels and lights ie 4 and 4 .
When lights_on(); method is executed in the Car class does the JVM reintializes the value ? How is the reference passed from bmwCar.lights_on to Car class lights_on method ? please provide detailed Answer about the workflow Thanks :)