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();
The identifier expected error is a compilation error, which means the code doesn't comply with the syntax rules of the Java language. For instance, one of the rules is that there should be a semicolon at the end of every statement. Missing the semicolon will cause a compilation error.
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.
class' expected. public class Calculator{ public Calculator(){ } public int sum(int one, int two) { int s = one + two; return int s; } } This error usually means that you are trying to declare or specify a variable type inside of return statement or inside of a method calls.
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
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