Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static

 
Smitha Ballikar
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
vinuharan haran
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The reason is local variable cannot be declared static.
thanks,
vinu.
 
RAMA KRISHNA AALLA
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think,

"Static methods can't have static variables or static blocks inside them"

Plz Correct me if i am wrong!


Cheers,
Rama Krishna Chowdary
 
Santana Iyer
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple reason as mentioned above,
main is a method and so can not have static modifier
for variable, only modifier allowed in method is final,

final int x=19;

hope this helps,
correct me if required.
 
Jyothi Bhogadi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Ramakrishna,
not only static methods... but i guess none of the method variables can have static as their modifier.....and only final is allowed and nothing else for a method variable.

Some body please correct me if i am wrong.

Regards
Sam
 
shashikanth penumadula
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
a local variable can have only a variable type and identifier.
it cannot have keywords like public , private, protected, final, static , transient or volatile.
 
Aakash Parashar
Ranch Hand
Posts: 123
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Smita,

static var i in main is not shadowing the class level variable i declared. static modifier for variables cannot be used insie methods, its a compile time error.
 
Smitha Ballikar
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks!!
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shashikanth penumadula:
hi
a local variable can have only a variable type and identifier.
it cannot have keywords like public , private, protected, final, static , transient or volatile.


variables can have final as modifier in local scope.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
err... u cant have local static varaibles. thats it
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic