Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static Random

 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
to generate random password...i use
static Random rand = new Random();
but on compilation, it gives "illegal start of expression error"..
what cud be the pro..??

tia
MB
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding a public private or protected befor the static
Steve
 
Gopi Balaji
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Malhar Barai:
hi all
to generate random password...i use
static Random rand = new Random();
but on compilation, it gives "illegal start of expression error"..
what cud be the pro..??

tia
MB

Static variables cannot be defined within methods. They should be enclosed within classes only.
Is this the problem?
-GB.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic