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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:49:53+00:00 2026-05-26T12:49:53+00:00

Im wondering how can I read a variable from one class’s to another? I

  • 0

Im wondering how can I read a variable from one class’s to another?

I have two class’s, triangle.java and screen.java

in triangle.java I have: public double bound=0;

how to I read that variable in Screen.java?

triangle.java:

public class triangle extends Activity
{

public EditText txtbound;
public double bound = 0;

txtbound = (EditText)findViewById(R.id.txtbound);

public double calculate()
{
    bound=Double.parseDouble(txtbound.getText().toString());

    // do maths here

}
}

and Screen.java has:

double bound1 = triangle.bound;   

this doesnt work, how to I get the variable in Screen.java? thanks!

  • 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-26T12:49:53+00:00Added an answer on May 26, 2026 at 12:49 pm

    make bound1 private in Screen class like

    private double bound1; //do not initialize fields here
    

    Use getters/setters in Screen like

        public double getBound() {
          return bound1;
        }
    
        public void setBound(double bound1) {
            this.bound1 = bound1;
        }
    

    In Triangle acquire instance of Screen:

    Screen scr = new Screen();
    scr.setBound(this.bound); --> this way the bound1 in Screen will have the value of bound from Triangle
    

    It’s a convention to name your classes starting with capital letters.
    You also don’t have to initialize your class fields when declaring them. Better
    use constructors for that.
    I suggest you read this tutorial to get more familiar with classes, fields and variables. Will save you time in the long run.

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

Sidebar

Related Questions

I was wondering how can I programmatically copy all the discussion items from one
I was wondering how can I read text of a control that doesn't have
I am wondering how I can read CSS comments out of a linked stylesheet.
I'm just wondering how I can read a text file in php, I'd like
I have read many php tutorials for logout scripts, i am wondering what could
I have been reading the Android documentation and I am wondering if anyone can
I have a data set which I read from my a .csv file. After
So I've taken over a VB.net web application project from another developer and have
I'm wondering if there are any libraries to read live MIDI input from a
I was wondering how can I set a timeout on a socket_read call? 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.