dmaster dmaster - 5 months ago 26
Java Question

"Illegal start of expression" error in Java

I have the following code in my main method:

public static String printMeme(Meme bear) {
return "The Meme of the month is" + getMemeOfTheMonth();


When I run this it gives me the error "illegal start of expression". I'm not too sure of why this is and an explanation would be greatly appreciated.

Many Thanks


I have the following code in my main method.

Exactly. What your code does is defines a new method for the class. You have to put it outside of your main method, or java will mistakenly try to run the code, which makes no sense when placed in the main method.

Keep in mind that you will need to call the method you made from inside the main method in order for the code to run:

public static void main(String[] args){

    // some code

    String s = printMeme(aMeme);