I am getting Java
Syntax error on token "callMe", Identifier expected after this token
on below line of my program:
c1.callMe();
class Class2 {
Class1 c1 = new Class1();
c1.callMe();
}
public class Class1 {
public void callMe() {
System.out.println("I am called!!");
}
}
In computer science, a syntax error is an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language. For compiled languages, syntax errors are detected at compile-time. A program will not compile until all syntax errors are corrected.
we get the identifier expected error. To fix the error, remove semicolons from the enum values. Sometimes the error may be much larger.
The <identifier> expected error is a very common Java compile-time error faced by novice programmers and people starting to learn the language. This error typically occurs when an expression statement (as defined in [3]) is written outside of a constructor, method, or an instance initialization block.
Class1 c1 = new Class1();
c1.callMe();
Must be moved to a method, it can't be at the class definition level, else it makes no sense (when would your code be executed??):
public class Class2 {
public void doSomething() {
Class1 c1 = new Class1();
c1.callMe();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With