Why sleep()is in Thread and wait() in Object class? Why can't
I have both in one class or vice versa?
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 |
What is java string pool?
What is type parameter in java?
How do you trim a space in java?
Are the equals() and hashCode() protected methods of object class?
How do you use compareto in java?
How many statements can be created with one connection in jdbc?
What is a memory leak in java?
What are encapsulation, inheritance and polymorphism?
Can we overload final method in java?
What is the difference between an array and an array list?
Explain about static imports in java?
Why main() method is public, static and void in java ?