Can I have multiple run methods in a class?

前端 未结 5 806
眼角桃花
眼角桃花 2021-01-03 03:21

If so, how? I need to have 2 run methods in each object I will instantiate.

I meant a run method for threading.

What i need is more like a race of two cars.

5条回答
  •  Happy的楠姐
    2021-01-03 04:18

    A class can't contain two methods with the same signature. The signature of a method is its name followed by its arguments.

    You may thus have run(int) and run(String) and run() in the same class. This is called method overloading. You can't have two run() methods, because you (and the compiler) could not know which one to execute when calling obj.run().

提交回复
热议问题