Download presentation
Presentation is loading. Please wait.
Published byRosalind Webb Modified over 9 years ago
1
JAVA METHODS (FUNCTIONS)
2
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
3
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)
4
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! }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.