Results 1 to 7 of 7
  1. #1
    jhuwalker is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Class & Constructor / Won't Comile

    Learning Class and constructor from web, kind of copy and modify Class and constructor to caculate Area. But it won't compile. Thanks
    --- --- ---
    /* Define a Class with Constructor */
    /* Calculate Area of Football Field and Basketball Court */

    public class Area {
    int length;
    int width;
    public int getArea () { // Method to calc Area
    reture (length*width);
    }

    Area() { //First Kind Of Constructor
    length=110;
    width=50;
    }

    Area(int l, int w) { //2nd Kind Of Constructor
    length = l;
    width = w;
    }

    Public static void main(String[] args) {
    Area fField, bCourt;
    fField = new Area();
    bCourt = new Area(40,30);

    System.out.println("footballField Area is " + fField.getArea());
    System.out.println("basketballCourt Area is " + bCourt.getArea());
    }
    }
    === compile error ===
    D:\java-code>javac consExecise.java
    consExecise.java:21: <identifier> expected
    Public static void main(String[] args) {
    ^
    1 error

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    the error is pointed out in the error message,
    Java Code:
    public 
    Public
    private
    Private
    which two are correct?

  3. #3
    jhuwalker is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Now, type error

    /* Define a Class with Constructor */
    /* Calculate Area of Football Field and Basketball Court */

    public class consArea {
    int length;
    int width;
    public int getArea () { // Method to calc Area
    reture (length*width);
    }

    consArea() { //First Kind Of Constructor
    length=110;
    width=50;
    }

    consArea(int l, int w) { //2nd Kind Of Constructor
    length = l;
    width = w;
    }

    public static void main(String[] args) {
    consArea fField, bCourt;
    fField = new consArea();
    bCourt = new consArea(40,30);

    System.out.println("footballField Area is " + fField.getArea());
    System.out.println("basketballCourt Area is " + bCourt.getArea());
    }
    }
    ========= Error ===
    D:\java-code>javac consArea.java
    consArea.java:8: cannot find symbol
    symbol : method reture(int)
    location: class consArea
    reture (length*width);
    ^
    1 error

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The compiler generated error points out the error, take a few minutes to consider the error, then look at the line of code and figure out what it should do. Neither of these errors are logic based, they are syntax errors when you find the area should it reture some value?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Are you planning on posting every little compiler error you get?

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    if you change Public to public and reture to return the code will compile and run. a lot of code "Won't Comile" if you don't watch your syntax. if you don't know the most expensive missing hyphen you should read this
    Last edited by j2me64; 03-01-2011 at 10:15 AM.

  7. #7
    jhuwalker is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Thanks

    Thank you all to give me great hint. I really learn from my mistake. Sorry I won't pay "Tolls"

Similar Threads

  1. Accessing Constructor from another Class
    By Java-Guy in forum New To Java
    Replies: 4
    Last Post: 01-19-2011, 05:41 AM
  2. How can I overide the parent class constructor?
    By AcousticBruce in forum New To Java
    Replies: 5
    Last Post: 01-12-2011, 04:13 PM
  3. comile with package
    By javastuden in forum New To Java
    Replies: 2
    Last Post: 01-04-2010, 07:29 AM
  4. Replies: 0
    Last Post: 12-19-2007, 10:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 10:01 AM

Posting Permissions

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