Results 1 to 2 of 2
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    2

    Default How can I use variables from one method in another?

    I am making a theatre bookings system, for each row in the theatre I made an array of seats. This was done in one method (I refer to it as the array method).

    I am now making an interface which will allow the user to check the total seats in the theatre, however, as I have made another method for the interface (to make it far easier to read), I don't know how I can transfer the value of ARRAYNAME.length to this other method for printing.

    I cannot make a variable called totalSeats in the array method and reference it in the userInterface method as the computer would be looking for a variable named totalSeats in the interface method.

    I also cannot make a totalSeats variable in the userInterface method and reference the arrays in the array method as once again, the current method would only be looked at.


    How can I get around this (preferably without having to re-write my entire program )

  2. #2
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    2

    Default Re: How can I use variables from one method in another?

    ah, doesn't matter, I've found it.

    I just need to declare it outside of any method.

Similar Threads

  1. Calling variables from another method
    By jwl in forum New To Java
    Replies: 2
    Last Post: 10-17-2012, 08:37 PM
  2. Calling variables from another method
    By jwl in forum Advanced Java
    Replies: 1
    Last Post: 10-16-2012, 04:45 AM
  3. Final variables in method
    By noobplus in forum New To Java
    Replies: 2
    Last Post: 03-04-2012, 03:32 PM
  4. Replies: 8
    Last Post: 10-24-2011, 10:34 PM
  5. accessing variables in a method that returns a void
    By mochajava in forum New To Java
    Replies: 2
    Last Post: 02-12-2011, 08:00 PM

Posting Permissions

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