Sunday, May 17, 2009

Published 5/17/2009 by with 0 comment

illegal start of expression

If a method is defined inside another method we may see ‘illegal start of expression’ error message. Remember that, we cannot define a method inside another method; we just can call a method inside another method. Sometimes it occurs just because of improper opening and closing of curly braces ( { or } ).

See the following example code:
public class IllegalStartOfExpression
{
public void methodA()
{
System.out.println("This is method A");

/* methodB is defined inside methodA because we didn’t close methodA before defining methodB*/

public void methodB()
{
System.out.println("This is method B");
}
}
}

Now see the solution:

public class IllegalStartOfExpression
{
public void methodA()
{
System.out.println("This is method A");
}

/* methodA is finished then, methodB is being defined*/
public void methodB()
{
System.out.println("This is method B");
}

}
    email this       edit

0 comments:

Post a Comment