Results 1 to 4 of 4
  1. #1
    Flamey is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Variables in MainMethod(). Local or Instance.

    Hi forum,

    I was wondering if anyone of you would help me.

    Are variables that are defined at the start of the mainMethod() Local or Instance?

    As I understand it, variables in a method are classed as Local.
    Variables defined in a class, but outside all methods are called Instance variables.

    So that would make the variables inside mainMethod() Local.

    But mainMethod() is a bit special, so I'd like to double check.

    Kind Regards

    Flamey

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Quote Originally Posted by Flamey View Post
    As I understand it, variables in a method are classed as Local.
    Variables defined in a class, but outside all methods are called Instance variables.
    Correct.

    So that would make the variables inside mainMethod() Local.

    But mainMethod() is a bit special, so I'd like to double check.
    Do you mean the method called main which is the main entry point into a program? The main method is not "a bit special" other than it is static. So yes any variables declared inside main are also local.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Quote Originally Posted by Flamey View Post
    but outside all methods are called Instance variables.
    Just to clear one thing up.
    Java Code:
    class Foo {
        static Bar b = new Bar();
    }
    In the above code the b variable is neither local nor an instance variable. It is a static variable.

  4. #4
    Flamey is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    Thank you very much Junky for you speedy and informative reply. :)

Similar Threads

  1. Instance variables
    By lala in forum New To Java
    Replies: 1
    Last Post: 01-26-2011, 05:38 PM
  2. Are Local variables thread safe ?
    By samson in forum Threads and Synchronization
    Replies: 6
    Last Post: 12-21-2010, 03:34 PM
  3. Local variables unavailable
    By Onra in forum New To Java
    Replies: 9
    Last Post: 11-25-2009, 10:39 PM
  4. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 05:48 PM
  5. Re-docking the Local Variables window
    By ScottVal in forum NetBeans
    Replies: 0
    Last Post: 01-20-2009, 08:59 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
  •