The code given below shows a Stackoverflow error when run.But if I make another class CarChange to create objects of Car ,it runs sucessfully. I am a beginner ,doing this code t
A stackoverflow usually means you have an infinite loop.
The reason you're receiving this is because you're calling drive from the testdrive method and in that method you're calling drive again.