• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Thread question required

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A implements Runnable {
int i;
public void run () {
try {
thread.sleep(5000);
i= 10;
} catch(InterruptedException e) {}
}
}
public class test {
public static void main (String args[]) {
try {
A a = new A ();
Thread t = new Thread (a);
t.start();
t.join();
int j= a.i;
}catch (Exception e) {}
}
}
E:\l>javac test.java
test.java:5: cannot resolve symbol
symbol : variable t
location: class A
t.sleep(5000);
^
1 error
Can somebody tell me why does it compile fail ?
Thanks !!
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,

Next time, please use the CODE UBB. It will preserve the indentation of your code.

sleep() is a static method of the thread class.
Use Thread.sleep(5000) instead of thread.sleep(5000)

Sheldon
 
PETER CARTER
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Thread.sleep(5000) instead of thread.sleep(5000)


Thanks !!
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic