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!
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:
publicstaticvoidmain(String[]args)
Best of luck on your work!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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!
The main method needs to remain as static, as per how Java defines programs. The instance variables (
width
, andheight
) 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 thestatic
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:Best of luck on your work!