“Class, Interface, Or enum Expected” error arises due to additional curly braces at end of Java program.

Considering an example where the file is named as wikitechy.java

Java Code
public class wiki {     
public static void main(String[] args) {
System.out.println(“Wikitechy welcomes you!");
}
}
}

1 error found:
File: wikitechy.java [line: 6]
Error: class, interface, or enum expected

We need to notice that two curly braces at the end of the program are at the same indentation level, which cannot happen in a valid program. So, if you get this same Class, interface or enum expected error next time, first check if there is an additional curly braces at end of program.

Simply delete one of the curly braces for the code to compile properly and check the code below :

Java Code
 public class wiki {     
public static void main(String[] args) {
System.out.println(“Wikitechy welcomes you!");
}
}

We can also identify this kind of error by pressing CTRL-A (to highlight the entire program) and then TAB (to correctly indent the highlighted code)

Compiler error: “class, interface, or enum expected”

Considering an example where the file is named as wikitechy.java

Java Code
import java.util.Random;
import java.Math.*;
import javax.swing.JOptionPane;
public static void wiki(String args[])
{
// a bunch of code
}
[ad type=”banner”]

In this program,  class declaration(wiki) is missing . Check the Java code below :

Java Code
public class wiki{                             
public static void wiki(String args[]){ ... }
}
[ad type=”banner”]

Categorized in: