Evan Corkrean
Evan Corkrean

Reputation: 1

Why is it an invalid method declaration when I am passing parameters?

    public class Store {
  // instance fields
  int area; 

  // constructor method
  public Calc(int one, int two, int three) {
    area = one*two*three;  
  }

  // main method
  public static void main(String[] args) {
    int sideOne = 2;
    int sideTwo = 3;
    int sideThree = 1;

    Calc mult = new Calc(sideOne,sideTwo,sideThree);

    System.out.println(mult.area);
  }
}

Can anyone help a beginner understand why, when passing parameters, this is an invalid method declaration?

Upvotes: 0

Views: 80

Answers (1)

Robby Cornelissen
Robby Cornelissen

Reputation: 97302

You define/call a Calc constructor, but there is no Calc class.

Rename your class to Calc ant your code will compile and execute correctly:

public class Calc {
    // instance fields
    int area;

    // constructor method
    public Calc(int one, int two, int three) {
        area = one * two * three;
    }

    // main method
    public static void main(String[] args) {
        int sideOne = 2;
        int sideTwo = 3;
        int sideThree = 1;

        Calc mult = new Calc(sideOne, sideTwo, sideThree);

        System.out.println(mult.area);
    }
}

Upvotes: 2

Related Questions