Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Threads
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Threads and Synchronization
why this code giving error
Johhn Davis
Greenhorn
Posts: 16
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class thread extends Thread { public static void main(String args[]) { thread d1 = new thread(); d1.start(); public void run() { try { for( int i = 0; i < 10; i++) { System.out.println("Welcome to threads: " + i ); Thread.sleep(1000); } } catch(InterruptedException e) { System.err.println("Sleep time is disturbed, you may get incorrect functionality. " + e); } System.out.println("Successful"); } } }
Eclipse displays error -----> at thread.main(thread.java:11)
shiva pandey
Greenhorn
Posts: 10
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You are putting method inside method . Put your run method outside the main.
Johhn Davis
Greenhorn
Posts: 16
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It reveals we can't defined a method inside another method. Is it ?
thanks for reply.
shiva pandey
Greenhorn
Posts: 10
posted 11 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Yes , we can not define method inside the method.
simon lin
Greenhorn
Posts: 3
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you meant to override the run method of the
thread
you are defining
public class thread extends Thread { public static void main(String args[]) { thread d1 = new thread(){ public void run() { try { for( int i = 0; i < 10; i++) { System.out.println("Welcome to threads: " + i ); Thread.sleep(1000); } } catch(InterruptedException e) { System.err.println("Sleep time is disturbed, you may get incorrect functionality. " + e); } System.out.println("Successful"); } }; d1.start(); } }
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Issue adding double value
overriding
Deadlock Example
rmi stub problem
urlyBird testing lock
More...