By each having a reference to the other. Eg your Car class is connected to your Person class via the driver variable. Inheritance is also called an "is a" relationship (Cat is a Mammal). You can also have a "has a" relationship (Car has a Driver)
When the hasDriver method is called you have to pass an instance of Person as a parameter. Inside the method that instance will be accessed by the name "drive", regardless of what the variable name may be in the calling method.
That misses a very important fundamental point about Java. In your examples the "number" variable contains the value 0, but the"drive" variable is not a Person object, and does not contain a Person object. It is a reference variable that contains a reference (pointer) to a Person object. Failure to make this distinction is behind many posts we get here when people don't understand what happens when you have two variables and one object.
ps I just saw another of your recent posts in which you tried to test an int != null. That's exactly the kind of mistake I had in mind!