I am getting Java "Syntax error on token "callMe", Identifier expected after this token" error 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!!");
}
}
kindly help me out to find the exact cause for this. Thanks in advance.
解决方案
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();
}
}