• Post Reply Bookmark Topic Watch Topic
  • New Topic

Illegal Start of expression  RSS feed

 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still tinkering away with Netbeans slowly grasping the rudiments of Java, but I'm still a little hazy as to the finer details of the class structure e.g.

I'm trying to move what is currently an inner class to its own class. When I create a new class in Netbeans I get the structure:

public class Bazaar {

/** Creates a new instance of Bazaar */
public Bazaar() {
public static final int BUYBEAST = 0;
//Gives error - Illegal Start of expression

public int showItem;
//Gives error - Illegal Start of expression

}
}

The trouble I'm having is with the default method "public Bazaar()". When I paste my code I can't define public or private variables.

Can anyone enlighten me as to why?

Thanks in advance

Paul.
 
Jens Mayer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

it is not allowed to use the modifier public, protected, private, static, etc. in methods or constructors. Only the modifier final is allowed in methods.

remove the modifier (to change them into local variables) or move the declarations out of the constructor like this:

public class Bazaar {

/** Creates a new instance of Bazaar */
public static final int BUYBEAST = 0;
public int showItem;

public Bazaar() {

}
}

this will compile.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!