Stackoverflow error

后端 未结 3 615
Happy的楠姐
Happy的楠姐 2021-01-21 14:29

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

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 15:07

    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.

提交回复
热议问题