/*
Java static method example
This Java Example shows how to declare and use static methods inside
a java class.
*/
public class StaticMethodExample {
public static void main(String[] args) {
int result = MathUtility.add(1, 2);
System.out.println("(1+2) is : " + result);
}
}
class MathUtility{
/*
* To declare static method use static keyword.
* Static methods are class level methods and can not access any instance
* member directly. However, it can access members of a particular object
* using its reference.
*
* Static methods are generally written as a utility method or it performs
* task for all objects of the class.
*
*/
public static int add(int first, int second)
{
return first + second;
}
}
Bookmark/Search this post with:
Nice Example
Nice Example...thank you very much
Good one
thanks for keeping the site
This site is super.. gr8 examples
thanx e lot
Good Site
This is really good site with nice examples.Thanks.
very usefulllll site..
examples r superb....
easy to understand...........
thank u........
treamendus my friend
really its a good plateform for studying
because u can learn only with the help of examples and u provide examples
best yaar!!!!!!
BOL
GOOD
EXAMPLES ARE VERY EASY, IT SHOULD BE LITTLE HARD WITH ANSWERS SO THAT WE CAN IMPROVE OUR PROGRAMMING KNOWLEDGE.
Good Examples
You have provided very understandable examples. It is a good site to learn and refresh the java basics. Thanks a lot.