Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Sunday

Static Methods in Java

2. Static Methods:
                              Static Methods belongs to the Class rather than the object.Static methods can be invoked without the need of objects.Statics variables can be modified by static methods.

Example:


public class HelloWorld{
static double pi = 3.14;
     static void calc(double a) {
pi = a;
System.out.println("Value pi is: "+a);
}
public static void main(String[] args) {
HelloWorld.calc(55.3);//accessing the static method
}
}

No comments:

Post a Comment