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

前端 未结 6 1708
时光说笑
时光说笑 2020-11-27 17:29

I have been troubleshooting this program for hours, trying several configurations, and have had no luck. It has been written in java, and has 33 errors (lowered from 50 befo

相关标签:
6条回答
  • 2020-11-27 18:02

    You miss the class declaration.

    public class DerivativeQuiz{
       public static void derivativeQuiz(String args[]){ ... }
    }
    
    0 讨论(0)
  • 2020-11-27 18:04

    class, interface, or enum expected

    The above error is even possible when import statement is miss spelled. A proper statement is "import com.company.HelloWorld;"

    If by mistake while code writing/editing it is miss written like "t com.company.HelloWorld;"

    compiler will show "class, interface, or enum expected"

    0 讨论(0)
  • 2020-11-27 18:12

    You forgot your class declaration:

    public class MyClass {
    ...
    
    0 讨论(0)
  • 2020-11-27 18:16

    Every method should be within a class. Your method derivativeQuiz is outside a class.

    public class ClassName {
    
     ///your methods
    }
    
    0 讨论(0)
  • 2020-11-27 18:16

    Look at your function s definition. If you forget using "()" after function declaration somewhere, you ll get plenty of errors with the same format:

     ... ??: class, interface, or enum expected ...
    

    And also you have forgot closing bracket after your class or function definition ends. But note that these missing bracket, is not the only reason for this type of error.

    0 讨论(0)
  • 2020-11-27 18:23

    the main method should be declared in the your class like this :

    public class derivativeQuiz_source{
        // bunch of methods .....
    
        public static void main(String args[])
        {
            // code 
        }
    }
    
    0 讨论(0)
提交回复
热议问题