Hello,
I am receiving an error when I try to create a constructor method. It makes no sense at all to me because right next to the program, I have a correctly compiled version of it. What is identifier expected?
What am I doing wrong?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello,
I am receiving an error when I try to create a constructor method. It makes no sense at all to me because right next to the program, I have a correctly compiled version of it. What is identifier expected?
What am I doing wrong?
Please copy the full text of the error message and paste it here. Also post the code(in code tags).
If you don't understand my answer, don't ignore it, ask a question.
Did you see the attached image?
Full error in BlueJ:
The symbol namd in the error message was expected to appear at this point in the code. It was not there; instead, there was some other symbol. Try to think about why this symbol may be expected here>
Correct version:
class Rectangle2 { private double length, width; public Rectangle2(double l, double w) // put instance variables inside constructor first { length = l; width = w; } public double area() { return length*width; } public Rectangle2 copy() { return new Rectangle2(length, width); } }
Version that won't compile
class Rectangle3 { private double length, width; public Rectangle3(double 1, double w) // error at this line { length = 1; width = w; } public double area() { return length*width; } public Rectangle3 copy() { return new Rectangle3(length, width); } }
In the one that won't compile, is that length variable an l or a 1 (one)?
It looks like a 1.
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
TSSF44 (October 28th, 2013)
That is a good example why I don't like images. If you do a Find for 1 in the posted source it finds the mistake.
No way to do a Find with an image.
If you don't understand my answer, don't ignore it, ask a question.