Results 1 to 4 of 4
  1. #1
    LeeB96 is offline Member
    Join Date
    Oct 2016
    Posts
    6
    Rep Power
    0

    Default Why is this not compiling?

    Hi, so I'm new to Java and am writing one of my first pieces of code. I cannot seem to figure out what is wrong with this code:

    public class lab{

    public static void main(String[] args){
    String ATM myATM = new ATM();
    myATM.go();
    }

    public void go(){
    System.out.println("Welcome to online ATM banking");
    System.out.println("How much do you want in your bank account?");
    System.out.println("Enter your number");
    System.out.println(go);
    }

    }

    An error message tells me that an ";" is expect on line 4 directly after the word "ATM" but this does not seem to make sense and when this is done I then have 4 new error messages telling me that the compiler cannot find a symbol for the ATM variable. Any help would be much appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why is this not compiling?

    Java Code:
          String ATM myATM = new ATM();
    That line has two datatypes: String and ATM where there should only be one.
    I assume that the datatype should be ATM not String because of the expression to the right of the =
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    LeeB96 is offline Member
    Join Date
    Oct 2016
    Posts
    6
    Rep Power
    0

    Default Re: Why is this not compiling?

    Ah okay thanks for the reply, my thinking was that ATM which is an object needed to be declared as a string datatype in order for it to be recognized. How would I go about declaring the ATM variable as a string datatype?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why is this not compiling?

    declaring the ATM variable as a string datatype?
    Java Code:
      String ATM;  // declare ATM to be a String
    Note java naming conventions for variables says that they should start with a lowercase letter.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Not compiling :(
    By Darkzombies in forum New To Java
    Replies: 14
    Last Post: 11-19-2012, 05:40 AM
  2. Compiling
    By yavo in forum New To Java
    Replies: 1
    Last Post: 12-24-2011, 01:23 PM
  3. Compiling help!
    By cloverrea in forum New To Java
    Replies: 9
    Last Post: 10-12-2011, 05:05 AM
  4. About compiling
    By edh in forum Advanced Java
    Replies: 2
    Last Post: 06-16-2011, 09:47 AM
  5. how to get compiling
    By philgrek in forum New To Java
    Replies: 1
    Last Post: 05-25-2010, 11:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •