• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Code on Threads

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,
Here is a code on Thread. I am getting an error during compilation saying - C:\Pallavi's\Javah\JCreator LE\MyProjects\Test1\Ex5.7\ThreadThread.java:23: cannot resolve symbol
symbol : constructor ThreadThread (java.lang.String)
location: class ThreadThread
ThreadThread counterA = new ThreadThread("Counter A");
The code is:

Please help me out .
Pallavi
[ March 30, 2003: Message edited by: Pallavi Chakraborty ]
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pallavi
ThreadThread.java u have mentioned does not have a constructor which takes 'String' as argument. 'Thread' class in java.lang package has a constructor that takes string argument, but constructor's are not inherited.
I have modified your code, and it compiles fine.. i have added in you code a constructor that takes an string argument and calls the super class constructor.

Hope this helps you
Reshma
 
Pallavi Chakraborty
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Reshma,
Thanks for your reply.
I do have a question. Is this required only for classes which extend Thread.
I coded something similar for a class implementing Runnable but didn't have to specify the construcor.
Here is the code :

Thanks for your help.
Pallavi
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pallavi,
This is not something specific to Thread class, but just an inheritance property. If you define a constructor urself, you must make sure that u invoke the appropriate version of the super class using super keyword. Runnable is just an interface, so theres no problem of super class constructor.
Thanks
Karthik.
 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pallavi,
In this case you are invoking a default constructor of the ThreadStuff class. when u donot specify any explicit constructor, the compiler adds a 0 argument constructor which will implicitly call the 0 argument constructor of the super class (in this case it is java.lang.Object class). This is same for all classes which donot provide a default constructor.
reshma
[ March 31, 2003: Message edited by: Reshma Pai ]
 
Pallavi Chakraborty
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Reshma & Karthik,
Thanks for bringing me on track. I was thinking
so narrowly about threads that I was even missing the BASIC things ..
Thanks again.
Pallavi
 
reply
    Bookmark Topic Watch Topic
  • New Topic