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


Please Help Members By Posting Answers For Below Questions

What is supplier in java?

571


I want to print “hello” even before main is executed. How will you acheive that?

668


What is threaded programming and when is it used? : Java thread

542


What is += mean in java?

550


What are different types of arrays?

542






Why you should not use singleton?

555


How do you use wildcards?

545


What is fail fast in java?

580


Explain different states of a thread in java?

596


What is xslt in java?

531


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?

531


Is array a class?

524


Write code to implement bubble sort in java?

564


Can substring create new object?

566


How do you join strings in java?

532