Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Static variable in java

  1. #1
    Junior Member vanshika's Avatar
    Join Date
    Apr 2013
    Location
    India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Static variable in java

    Why cant we declare static variable in main method??
    vanshika..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,579
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Static variable in java

    Variables declared in methods are local to that method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member vanshika's Avatar
    Join Date
    Apr 2013
    Location
    India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Static variable in java

    can u explain in depth..??
    vanshika..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,579
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Static variable in java

    The authors of java didn't want that feature and didn't put it in the language.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. putting a non static variable in a static variable
    By beennn in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 23rd, 2012, 04:06 PM
  2. Replies: 4
    Last Post: November 14th, 2012, 11:09 PM
  3. Replies: 10
    Last Post: October 26th, 2011, 02:22 PM
  4. [SOLVED] non static variable this cant be referenced from a static context
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 20th, 2011, 06:13 PM
  5. non-static variable
    By frozen java in forum What's Wrong With My Code?
    Replies: 11
    Last Post: June 15th, 2011, 06:18 PM