Win a copy of Create an Uber Clone in 7 Days: Build a real world full stack mobile app in Java this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

static variable  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me why we cannot declare a static variable inside a method? Is it because static variables are class level variables?
 
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be the use of it? Variables declared inside the method body are local variables to that method; they can't be accessed outside of it.
 
Marshal
Posts: 59467
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
As KS has told you, there is no point; static members belong to the class, and something declared in the method is a local variable which belongs to the method.
 
soumik paul
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clarifying it fo me.
 
Campbell Ritchie
Marshal
Posts: 59467
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!