Wednesday, July 22, 2009

Puzzle 43 – Solution

The way to stop the code from printing STOP ME IF YOU CAN is to rename the run() method. Since MultiThreader implements Runnable the run method is required. A default implementation of the run method can be obtained by extending the Thread class.

package com.twisters;
class MultiThreader extends thread implements Runnable{ /*15 additional char */

public void _run(){ /*1 additional character */

public static void main(String[] args) {
MultiThreader m
= new MultiThreader();
Thread t
= new Thread(m);

The other way to prevent the code from running the main method itself is to throw an exception in a initializer which would do the trick too!!

My solution pick of the week - Vishwanath's Solution - I just love out of the Box Solutions!

Scores for this puzzle will be updated next week!!!

1 comment:

  1. //2 class MultiThreader extends thread implements Runnable{ //

    it is compilation error because there is no such class thread(Lower t in thread) exists . it is ok if there is a class "thread" in the package com.twisters

    and because there is no run() method which is abstract method in Runnable interface it is again another compilation error


Solution for this question?