Results 1 to 4 of 4
- 05-16-2011, 02:56 AM #1
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0
Getting illegal start of expression in main
class Mug{
Mug(int marker)
{
System.out.println("mug ("+ marker +")");
}
public void f(int marker)
{
System.out.println("f(" +marker+ ")");
}
}
class Mugs{
static Mug m1;
static Mug m2;
static{
m1 = new Mug(1);
m2 = new Mug(2);
}
//m1.f(1);
//m2.f(2);
Mugs()
{
System.out.println("the Mugs object is being created");
}
void print()
{
System.out.println("initializing mugs");
}
}
/**
*
*
*/
public class NonStaticInit {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
static Mugs mm1 = new Mugs();
}
}
- 05-16-2011, 03:01 AM #2
You cannot have static there.
- 05-16-2011, 03:35 AM #3
To be more precise... Static variables and objects are only used outside of method declarations, never inside of them. So remove the "static" from Mugs mm1=new Mugs(); and you should be fine. Assuming the java-file is called NonStaticInit.java, that is.
- 05-16-2011, 04:37 AM #4
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Illegal start of expression
By lodaSchitt in forum New To JavaReplies: 2Last Post: 04-28-2011, 10:04 PM -
Illegal Start of Expression
By Tyre in forum New To JavaReplies: 20Last Post: 04-15-2011, 02:50 PM -
Illegal start of expression
By Tekila in forum New To JavaReplies: 10Last Post: 03-04-2011, 12:23 AM -
Illegal start of expression
By Basit56 in forum New To JavaReplies: 2Last Post: 08-18-2009, 09:12 AM -
Illegal Start of Expression
By vince425 in forum New To JavaReplies: 3Last Post: 10-18-2008, 07:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks