Java: Identifier expected Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Java: Identifier expected without wasting too much if your time.

The question is published on by Tutorial Guruji team.

What’s the issue here?

class UserInput {
  public void name() {
    System.out.println("This is a test.");
  }
}

public class MyClass {
  UserInput input = new UserInput();
  input.name();
}

This complains:

<identifier> expected
   input.name();

Answer

Put your code in a method.

Try this:

public class MyClass {
    public static void main(String[] args) {
        UserInput input = new UserInput();
        input.name();
    }
}

Then “run” the class from your IDE

We are here to answer your question about Java: Identifier expected - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji