This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help please  RSS feed

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have modified the Phrase o matic program given in head first java a little and am having problems as to why I am not bieng able to work. The code I have given below.
Plese note when I take out "public" from "public String[] wordList={"24/7","multi-Tier","30,000"};" It works, meaning that the String[] works with only default access. why so?


public class PhraseOmatic{
public static void main(String[] args){
System.out.println("The phrase of the day is"+givePhrase());
}

public static String givePhrase(){
public String[] wordList={"24/7","multi-Tier","30,000"}; //problem here
int random=0;
random=(int)(Math.random()*wordList.length);
return wordList[random];
}
}
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Variables declared within the definition of a method are local variables. Local variables don't take access modifiers as they can only be accessed by the method.

Henry
 
Sanjaya Sugiarto
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to Henry's comment:

the local variables can only be applied by one modifier: final
[ October 21, 2006: Message edited by: Sanjaya Sugiarto ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!