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

  • Home
  • SEARCH
  • 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 7418841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:57:28+00:00 2026-05-29T07:57:28+00:00

I have multiple classes that have a common variable with the same name. Say

  • 0

I have multiple classes that have a common variable with the same name.
Say a string variable “str”.

I have a thread class say “thread_update_str”

What I need to do is make the str variable in the class from which it is called to the current datetime from the method run of the thread.

Could anyone help me figure how could I achieve something like this
Any help would be appreciated …

Thanks a lot

Also I do not necessarily need the value of str to be same across all classes.

Class abc
{
    String str = "a";
    new str_Thread().start();
    System.out.println(str);
}

Class xyz
{
    String str = "x";
    new str_Thread().start();
    System.out.println(str);
}

Class lmn
{
    String str = "l";
    new str_Thread().start();
    System.out.println(str);
}

public class str_Thread extends Thread {

public void run() {
    for (int i = 1; i > 0; i++) {
        try {

            //make the str variable equal to i.toString();
            sleep((int)(10000));

        System.out.println("DONE!"+i);
        } catch (Exception e) {e.printStackTrace();}
    }
}
}
  • 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-29T07:57:30+00:00Added an answer on May 29, 2026 at 7:57 am

    Your classes should implement an interface with the method

    void setStr(String str);
    

    And your thread-class gets the object where to set the String as constructor arg.

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

Sidebar

Related Questions

Is it possible to have multiple classes that inherit/extends same class in Google AppEngine
I have multiple classes that all derive from a base class, now some of
The situation: I have multiple classes that should each hold a variable with a
In Django, when you have a parent class and multiple child classes that inherit
I have a C# singleton class that multiple classes use. Is access through Instance
Say we have a class inheriting from two base classes (multiple inheritance). Base class
Can classes have multiple constructors and/or copy constructors in common-lisp? That is - in
I have a common library where I've put classes that are used between multiple
I have multiple classes that inherit from one base class, and each class is
I am having multiple Services in my application.i have a datacontract that i need

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.