ye i forgot to put on // on that line Calculator.sum(num1, num2);, so the compiler ignores my statement and use yours. but oh my god.. changing static int print() { to static void print() { did it, now it works...
since days i was caught up on other parts of the code and totally ignored this very line when i started to understand about objects chapter. thanks man for ruling that one out!! finally i can move on in the exercises xd
btw: that was the example code after i put my code into, so i could see theirs:
import java.util.Scanner;
public class ObjectFunctionality {
public static void main(String args[]) {
Printer thing = new Printer();
thing.Print();
}
}
class Printer {
int firstNumber, secondNumber, result;
Scanner reader = new Scanner(System.in);
Calculator counter = new Calculator();
Printer() {
System.out.print("Type in the first integer: ");
firstNumber = reader.nextInt();
System.out.print("Type in the second integer: ");
secondNumber = reader.nextInt();
result = counter.Sum(firstNumber, secondNumber);
}
public void Print() {
System.out.println("Sum of the numbers: " + result);
}
}
class Calculator {
static int Sum(int first, int second) {
int sum = first + second;
return sum;
}
}