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 6210577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:11:05+00:00 2026-05-24T06:11:05+00:00

so I was watching a tutorial and I am trying to understand this syntax

  • 0

so I was watching a tutorial and I am trying to understand this syntax

  Thread thread = new Thread()
    {     
  //if i declare variables here i get errors
            public void run()
            {
            // ....define variables in function
           }
    }

How does this code work? I think when the thread object is created, it defines adds or “appends” a function to its “list” of functions? So thread.run() or thread.start() can be called later. I’m not sure I’m guessing..can someone enlighten me. From the tutorial I watched in the run function he did this

//the same run that is in the Thread class
public void run()
{
  int timer = 0 ;
  while(timer < 5000)
  {
     sleep(100) ; 
     timer+=100;
  }
}

What does sleep do? I’ve googled it but couldn’t find anything good. Does it basically stop the current application for 100 ms before it continues with the loop? which means sleep is called 50 times? I’m terrible at maths lol..but if that is so, is the code above equivalent to

public void run()
{
  int timer = 0 ;
  while(timer < 50)
  {
     sleep(100) ; 
     timer++;
  }
}

However I know the simplest method would just be to say sleep(5000) ;

Clearly, I’m a noob at this..so will appreciate any explanation..the thorough the better thanks. Sorry, no Idea how to use code tags..

  • 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-05-24T06:11:06+00:00Added an answer on May 24, 2026 at 6:11 am

    its not possible because its like trying put instance variables inside an instance which is not

    possible.. we are giving an implementation only for a single instance.. and you cannot have an

    instance variable defined specifically for a single Object.. and sleep(100) stops the execution of

    current thread for 100 milliseconds and it happens for 50 times.. that means 50*100 milliseconds..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to rails, and I'm watching this video tutorial online and I was
I'm trying RubyMine, and watching this tutorial https://www.jetbrains.com/ruby/documentation/ . The author uses there project->new->scaffold
I am watching the ASP.NET learn videos on asp.net/learn. In this tutorial, they are
I've been watching this tutorial http://windowsclient.net/learn/video.aspx?v=296114 . At the very begining empty Windows forms
hi i'm watching a c++ tutorial and instructor includes the libraries like this #
From what I understood watching the Android tutorial, to reference a new class you
i am watching this tutorial. at around 15:40, the speaker said something like a
i have some questions when watching this tutorial. i wonder when i overwrite methods,
I was watching a tutorial on Rails and was very impressed that you could
I found the following table structures while I was watching ruby on rails tutorial.

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.