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
What is supplier in java?
I want to print “hello” even before main is executed. How will you acheive that?
What is threaded programming and when is it used? : Java thread
What is += mean in java?
What are different types of arrays?
Why you should not use singleton?
How do you use wildcards?
What is fail fast in java?
Explain different states of a thread in java?
What is xslt in java?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?
Is array a class?
Write code to implement bubble sort in java?
Can substring create new object?
How do you join strings in java?