Static Method in Java Example Program. You can find Static member method in Java with Example Program (code snippets) in this page.
class StaticMemberMethod{
private static int count;
private static int data;
static{
count = 0;
}
public StaticMemberMethod(){
count++;
}
public static void displayCount()
{
data = 123;
System.out.println(“\n\tCount value is: ” + count);
System.out.println(“\n\tValue of data: ” + data);
}
}
public class StaticMemberMethodDemo{
public static void main(String args[]){
StaticMemberMethod ob1,ob2,ob3;
ob1 = new StaticMemberMethod();
ob2 = new StaticMemberMethod();
ob3 = new StaticMemberMethod();
StaticMemberMethod.displayCount();
ob2.displayCount();
}
}
Result:
Count value is: 3
Value of data: 123
Count value is: 3
Value of data: 123