Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Resolve Symbol

Status
Not open for further replies.

alexpalmbay

Technical User
Sep 1, 2002
6
US
I'm new to JAVA, so please handle w/care:)

I'm trying to write a simple rectangle pgm, but I'm getting the following errors:

Rectangle.java:24: cannot resolve symbol
symbol : variable calculateArea
location: class Rectangle
Sytem.out.println(Rectangle.calculateArea);

Below is my pgm:

/*
* File: Rectangle.java
* Description: This program represents a geometric rectangle.
*/

public class Rectangle
{
private double length = 3; // Instance variables
private double width = 4;

public Rectangle(double l, double w) // Constructor method
{
length = l;
width = w;
}
public double calculateArea() // Access method
{
return length * width; // calculateArea()
}

public static void main(String argv[])
{
System.out.println(Rectangle.calculateArea);
}
}//end of pgm

I'm using jdk1.3.1_04, which I download off the SUN/JAVA website. As I said, I'm new to JAVA, so I'm sure the answer is very simple.

Thank you very much for your help!
 
You are missing some parens and you need to create an instance of your object before you can use its instance methods. Remember, main() is a static method (belongs to the class as a whole) and cannot directly can an instance method without first creating an instance of the object. Your main() should look something like:
Code:
public static void main(String[] args) {
  Rectangle r = new Rectangle(2,3);
  System.out.println(r.calculateArea());
}
 
Thank you very much for your assistance. It works now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top