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
How we can execute any code even before main method?
What is the largest data type in java?
What are the different types of sorting in java?
Tell me how many ways are there to initialise an integer with a constant.
What are triggers in DB? Explain their types. How do they work?
What is meant by anonymous class?
You're given a Boolean 2D matrix, can you find the number of islands?
Which class is used by server applications to obtain a port and listen for client requests?
What are heterogeneous objects?
Why destructor is not used in java?
Give reasons supporting that string is immutable.
How many types of equations are there?
What is difference between path and classpath?
How do you escape a string?
What is a “stateless” protocol ?