Results 1 to 9 of 9
  1. #1
    Lyricid is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Exclamation Print Variable From One Class to Output on another.

    I am basically trying to get one variable from lets say class A to be part of a if statement in part B?

    is there any way of doing this?

    i have imported Class A to Class B

    looked every where still coming up with no answers.


    Class A Code Snippet

    Java Code:
    int m = 456;
    Class B Code Snippet
    Java Code:
           if (result == result) {
           System.out.println("Decryption Successful");
           System.out.println("");
           System.out.println("-------------------------------------------");}
           else if (o != result) {
           System.out.println("Decryption Unsuccessful");
           System.out.println("");
           System.out.println("-------------------------------------------");

    What I want it to do is basically here ----> if (m== result) <----- where m is the variable from CLASS A??
    Last edited by Lyricid; 02-27-2010 at 01:58 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Lyricid is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Default

    i have tried so much but it is just not working .... how would i go about writing that code? any information is helpful thank you in advance

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Lyricid View Post
    i have tried so much but it is just not working .... how would i go about writing that code? any information is helpful thank you in advance
    By showing us first what you've tried and describing in greater detail what isn't working. Else, how do we guess what you're doing wrong? "it is just not working ..." tells us zip.

  5. #5
    Lyricid is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Default

    when i try to add in CLASS B

    Java Code:
    Encrypt a = new Encrypt();
    a.message = 456
    i get a error whilst compiling! m = message btw!

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    Lyricid is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Default

    yes thats the variable in CLASS A but i want to use it in a if statement in CLASS B

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Lyricid View Post
    when i try to add in CLASS B

    Java Code:
    Encrypt a = new Encrypt();
    a.message = 456
    i get a error whilst compiling! m = message btw!
    What error message? Perhaps you should show more code too?

  9. #9
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default

    why dont you create a method in your Class A

    Java Code:
    public int getValue()
    {
       return <int variable that you need to get>;
    }
    and then say
    Java Code:
    if(result == <object name>.getValue();
    {
      blah blah blah
    }
    Let me know if it works :)

    Good luck
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

Similar Threads

  1. variable output is always 0
    By 1Sserdda in forum New To Java
    Replies: 2
    Last Post: 09-25-2009, 06:26 AM
  2. Replies: 3
    Last Post: 03-19-2009, 05:00 PM
  3. print variable with paint(Graphics g) ??
    By tghn2b in forum New To Java
    Replies: 10
    Last Post: 12-29-2008, 12:11 PM
  4. Interface variable to class
    By zill in forum Advanced Java
    Replies: 6
    Last Post: 10-11-2008, 03:29 AM
  5. how to print output on same line in 'while loop'?
    By acidblue in forum New To Java
    Replies: 5
    Last Post: 12-13-2007, 02:30 AM

Posting Permissions

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