Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:54:41+00:00 2026-06-15T17:54:41+00:00

In the below code what could be the predicted output? public class Threads2 implements

  • 0

In the below code what could be the predicted output?

public class Threads2 implements Runnable {
    public void run() 
    {
        System.out.println("run.");
        throw new RuntimeException("Problem");
    }

    public static void main(String[] args) 
    {
        Thread t = new Thread(new Threads2());
        t.start();
        System.out.println("End of method.");
    }
}

The possible outcome given as the answers are:

End of method.
run.
java.lang.RuntimeException: Problem 

OR

run.
java.lang.RuntimeException: Problem 
End of method.

According to me only answer 2nd is possible, please help me to understand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:54:41+00:00Added an answer on June 15, 2026 at 5:54 pm

    The execution will result in two threads, the main thread (the one running the main-method), and the thread created in the main method. Since you can’t guarantee anything when it comes to the order that the threads will run, there are multiple orders that the code could run.

    So lets call the main thread Thread1, and the created thread Thread2. The possibilties then are, after Thread2 has been started:

    1. Thread1 gets the processor time first. (“End of method…” get printed first)
    2. Thread2 gets the processor time first. (“run” get printed first)

    and, there is actually a third possibility (i think):

    1. Thread2 get the processor time and prints “run”.
    2. Thread2 gets interupted, and Thread1 takes over.
    3. Thread1 prints “End of…”
    4. Thread2 throws the exception.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with the below code and was hoping someone out there could
Could you please have a look at my code below. #!C:\Perl\bin\perl.exe use strict; use
Could anyone help me in assessing why the code below doesn't work. I'm using
Given the Java code below, what's the closest you could represent these two static
Could someone please help me with the code for below requirement or scenarios...I achieved
The code I have below works fine but I'm sure it could be more
below code is my databasehandler class i got it from a tutorial. Beside that
I got the below code from some example code. What could possibly cause it
I get a java.lang.ClassNotFoundException , when I execute the below code. Could someone explain
when I run the below code I got error in line echo $attribute; The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.