Results 1 to 13 of 13
Like Tree4Likes
  • 2 Post By gimbal2
  • 1 Post By pj6444
  • 1 Post By gimbal2

Thread: What is the result of compiling and running the following program?

  1. #1
    blerimz is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default What is the result of compiling and running the following program?

    public class ThreadMain {
    public static void main(String[] args) {
    TestThread th = new TestThread ("TestThread");
    th.start(TestThread.MIN_PRIORITY);
    }

    public void run(){
    System.out.println("ThreadMain - run");
    }
    }

    class TestThread extends Thread{
    public TestThread(String name){
    super(name);
    }

    public TestThread(Runnable runnable){
    super(runnable);
    }


    public void start(int val){
    System.out.println(getName()+" - start");
    super.start();
    }

    public void run(){
    System.out.println(getName()+" - run");
    TestThread thread = new TestThread(new TestRunnable());
    thread.start();
    }
    }

    class TestRunnable implements Runnable{
    public void run() {
    System.out.println("TestRunnable - run");
    }
    }

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,023
    Rep Power
    6

    Default Re: What is the result of compiling and running the following program?

    Upon compilation there are two possible outcomes.

    1. you get compile errors because the code is wrong
    2. it compiles

    Upon running there are three possible outcomes.

    1. it runs, but throws an exception because there is a bug
    2. it runs, doesn't produce an exception but produces the wrong results
    3. it runs and works as designed

    So yeah, go do it yourself. Compile it and if that works, run it and see what happens. Fingers crossed!
    Last edited by gimbal2; 02-20-2014 at 12:12 PM.
    blerimz and pj6444 like this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    blerimz is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Re: What is the result of compiling and running the following program?

    thank you for your reply .

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,023
    Rep Power
    6

    Default Re: What is the result of compiling and running the following program?

    Really, that was the answer you wanted? I was basically making a joke.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    blerimz is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Re: What is the result of compiling and running the following program?

    well im new in java programming so ...

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,023
    Rep Power
    6

    Default Re: What is the result of compiling and running the following program?

    I get that. What I don't get is why you then have code with threading. That's an incredibly advanced topic. Also "a test" ?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    blerimz is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Re: What is the result of compiling and running the following program?

    university brother university .

    So do u know whats the output of that ?

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: What is the result of compiling and running the following program?

    Well, have you TRIED it yet?

  9. #9
    blerimz is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Re: What is the result of compiling and running the following program?

    What is the result of compiling and running the following program?-untitled.png

  10. #10
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    164
    Rep Power
    2

    Default Re: What is the result of compiling and running the following program?

    Congratulations! That is your output. All you had to do was compile and run it.
    blerimz likes this.

  11. #11
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,023
    Rep Power
    6

    Default Re: What is the result of compiling and running the following program?

    University, and then this thread is created :s I just can't believe it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    blerimz is offline Member
    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Default Re: What is the result of compiling and running the following program?

    its just a thread ......

  13. #13
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,023
    Rep Power
    6

    Default Re: What is the result of compiling and running the following program?

    Let's keep it at that. But I hope you get the clue soon.
    PhHein likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Problems with running and compiling application
    By lugaru in forum New To Java
    Replies: 1
    Last Post: 07-02-2012, 12:12 AM
  2. hi the program is compiling but not running why
    By javastuden in forum New To Java
    Replies: 6
    Last Post: 09-21-2010, 09:14 AM
  3. Compiling/Running in Command Prompt
    By coke_in_a_can in forum New To Java
    Replies: 12
    Last Post: 05-31-2010, 09:05 AM
  4. my code compiling but not running
    By girishkumar in forum New To Java
    Replies: 16
    Last Post: 03-16-2010, 04:45 PM
  5. Importing / compiling and running with .jar package
    By splinter64uk in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 02:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •