Skip to content
Advertisement

getting error while compiling java program

i’m getting this error while compiling the java program to find the area of square & rectangle using overload constructor .

JavaScript

this is my code

JavaScript

Advertisement

Answer

You have multiple errors in your file:

JavaScript

There is no variable l1 and b1. You want to rename your method parameters.

JavaScript

Static is not a valid keyword. You want to use static. And you don’t want the semicolon at the end of the line.

But also – static is not allowed here. You either need to declare your square class in a separate file or you need to make it static

JavaScript

Also finally your label “2” in the switch case is duplicated.

JavaScript

I found all that just by copying your code into an IDE.

Further I would suggest:

  • Class names should start with an uppercase Letter. So use Area instead of area and Shape instead of shape.
  • Move every class to a separate file, so you have a Area.java and Shape.java
  • Format your code for readability
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement