DEV Community

Discussion on: FIXED: Troubles in Java please help, my teacher has been ignoring my questions for almost a week

Collapse
 
drakendel profile image
Chance Walker • Edited

I tried it this was the result:
Error: Main method is not static in class com.eclipse.chancewalker.rectangleTestCW, please define the main method as:
public static void main(String[] args)

But I did need to delete the static for the private double's, so thank you so much for the help!

Collapse
 
hunter profile image
Hunter Henrichsen • Edited

The main method needs to remain as static, as per how Java defines programs. The instance variables (width, and height) are the ones that should not be static. Instance variables are variables that belong of specific occurrences, or "instances," of a class. Each rectangle should have its own length and width, and shouldn't care about what any other rectangle does. That's how variables work without the static keyword, and these are called instance variables.

If you were to keep track of how many rectangles existed, it would make sense to have a private static int count variable that didn't need to be different for each rectangle. Static links the variable to the class rather than one instance.

The main() method signature should look like this, as always:

public static void main(String[] args)

Best of luck on your work!