Why this code does not work?
HelloWorld.java:5: error: non-static method add(int,int) cannot be
referenced from a static context System.out.println(add(1,2));
- I know if I add static to the add method, it works, but why we have to use static? If this code was in C, it works, right?
if you do not add static to add method, what are other ways that I can "test" my add method in main?
public class HelloWorld { public static void main (String []args) { System.out.println(add(1,2)); } public int add (int x, int y) { return x+y; } }