Why sleep()is in Thread and wait() in Object class? Why can't
I have both in one class or vice versa?
Answer Posted / ismail
In Java "Object" class is super for all classes and every
entity we consider as object in java. Every object in java
has default behaviour of "Object" class.
Now come to the point, When you instantiate a thread you
may require to stop a while that particular thread.So
Thread class has sleep method.
But in the situation of multithreading, you may require wait
() and notify() methods so that you can invoke "Object"
class behavior to your class.
| Is This Answer Correct ? | 7 Yes | 3 No |
Post New Answer View All Answers
Explain the use of javap tool.
What is difference between variable declaration and definition?
What is the hashcode () and equals () used for?
When we should use serialization?
give an example for encapsulation?
What are basic keywords?
Is java code slower than native code?
What is the main functionality of the remote reference layer?
What classes of exceptions may be caught by a catch clause in java programming?
What is a line break example?
Why to use nested classes in java? (Or) what is the purpose of nested class in java?
How many bits is a string?
Define packages in java?
Which access specifier can be used with class ?
What is the difference between path and classpath variables?