• Post Reply Bookmark Topic Watch Topic
  • New Topic

static method in class Thread

 
Lawrance Miao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static methods in class Thread like sleep(), currentThread(),when we write them in our code, they could know the running thread object. How ??
Why a static method can access an object of its own class ??
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
currentThread(), sleep() etc contain native method calls to perform their respective functions. That's y there are static (they dont access any instance variable or methods).

Iam not sure I understand ur second question,
>Why a static method can access an object of its own class ??
well, why not, if the class has a stic variable of same type as the class, why not ?

look at code below.



though u would want to take a good hard look at ur design to decide if theresnt a better way to do this.

tx,
ram.
 
Lawrance Miao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx ram . I think I get it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!