JAVA METHODS (FUNCTIONS)
Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects Functions are not inside of objects
Static Method/Function Template public static RETURNTYPE NAME(PARAMETERS) { } Notes: Methods are defined in the class void can be used if you do not return anything Parameters must have type declarations as well e.g. void methodName(int x, int y)
Method Definition & Call Example public static double slope(double x1, double y1, double x2, double y2) { double m = (y2-y1)/(x2-x1); return m; } public static void main(String [] args) { double a = 1.0, b = 2.0, c = 3.0, d=4.0; double mySlope = slope(a, b, c, d); //without the slope() method call, nothing would happen! }