O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exam Prep Practice Questions

Question 1 You are creating a class that extends Object and implements Runnable. You have already written a run method for this class. You need a way to create a thread and have it execute the run method. Which of the following start methods should you use?
  • A.

    public void start(){
        new Thread( this ).start();
     }
    
  • B.

    public void start(){
       Thread myT = new Thread();
       myT.start();
    }
    
  • C.

    public void start(){
       Thread myT = new Thread(this);
       myT.run();
    }
    
A1: Answer A is correct. It correctly creates a new thread attached to the runnable object and starts it. It does not matter that there is no reference to the thread in the start method. Answer B is incorrect because the new thread is not attached to the runnable object, so it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required