I have created two classes. In the first class, I have tried to make a method in another class to return a value with a command to output value on the console. But I get an error that says there are incompatible types. Here are two classes that I have created and I wanted to make a calculator out of that: The first class
class calc1
{
public static int num1; //first number variable
public static int num2; //Second number variable
public static String op; //Operatior variable
public static void main(String[] args) //
{
num1 = Integer.parseInt(args[0]);
num2 = Integer.parseInt(args[2]);
op = args[1];
calc3.calculate(op); //Calling method from the second class with an arugement.
}
}
this is the second:
class calc3
{
public static int calculate(String ops)
{
switch(ops) //I believe that ops stores value from op variable in the first class.
{
case "+":
{
int num = calc1.num1 + calc1.num2;
return (System.out.println(num));
}
}
}
}
Here is an error message I get from a compiler:
Desktop$ javac calc1.java
./calc3.java:10: error: incompatible types
return (System.out.println(num));
^
required: int
found: void
1 error
PS. I was wondering if that the process I am doing is called overloading methods?