File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question on threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question on threads" Watch "A question on threads" New topic

A question on threads

Rajani Sudhakar
Ranch Hand

Joined: Apr 28, 2004
Posts: 60
I have the following qwestion ...
Can anyone explain me the answer?

What will happen when you attempt to compile and run the following code?

class TSamp extends Thread{
public native String getTime();

public class Multi implements Runnable {
boolean bStop;
public static void main(String argv[]){
Multi m = new Multi();
public void go(){
TSamp ts = new TSamp(this);

public void run(){


Answer : Compile time error.

Thanks in advance,
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
The problem is that you're trying to invoke a constructor that doesn't exist.

Look at the TSamp class. How many constructors do you see? None. That means that the only constructor that class has is the default constructor, which takes no arguments. In your code, you have this line:

This tries to invoke the TSamp constructor that takes a Multi object. No such constructor exists!

If you put this into your TSamp class, it'll work just fine:

That will take the Multi object, which is a Runnable object, and pass it along to constructor in Thread.

SCJP Tipline, etc.
Rajani Sudhakar
Ranch Hand

Joined: Apr 28, 2004
Posts: 60
Hi Corey..


Yeah.. there is no constructor
I was a bit confused..

Thankyou so much..

I agree. Here's the link:
subject: A question on threads
It's not a secret anymore!