Lee Lee - 1 month ago 6
Java Question

Why will this not compile?

So the following code has errors


"go" has no identifier


But I thought when I declared "go" as a String type variable that this gave an identifier to the variable "go"?

Obviously I've got it messed up somewhere as I'm new to Java (and coding in general) so I was wondering how I would identify the variable "go" and resolve the issue in which I'm facing. Thanks in advance.

Here is the code:

public class ATM {

public static void main(String[] args){

String ATM;
ATM myATM = new ATM();
myATM.go(); }

public class go {

String go;
go = "Welcome to online ATM banking";
go = "How much do you wan in your account?";
go = "Enter your number";

System.outprintln(go);
}}

Rao Rao
Answer

There are few trivial issues:

  • go is a method not a class
  • typo in print statement

Here is complete updated class which compiles.

public class ATM {

 public static void main(String[] args) {

  String ATM;
  ATM myATM = new ATM();
  myATM.go();
 }

 public void go() {

  String go;
  go = "Welcome to online ATM banking";
  go = "How much do you wan in your account?";
  go = "Enter your number";

  System.out.println(go);
 }
}
Comments