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
It sounds like you might have some infinite recursion happening.
drive() calls testdrive() which class drive() which calls testdriver()...forever, or until you run out of memory, hence your stack overflow error.
drive()
testdrive()
class drive()
testdriver()