Java: why Thread.sleep() and yield() are static?

后端 未结 6 391
庸人自扰
庸人自扰 2021-01-03 19:56

Why sleep() and yield() methods are defined as static methods in java.lang.Thread class?

6条回答
  •  渐次进展
    2021-01-03 20:51

    They are static so that overriding concept can be avoided i.e.

    When they are called with parent class reference to hold child class object like situation it implements Method Hiding concept and not overriding due to Static method nature, i.e parent class(here thread class) method will run which have the complete functionality of sleep and yield.

    http://i.stack.imgur.com/goygW.jpg

提交回复
热议问题