Static methods are those methods that are defined using static keyword. If you define any method as static you don’t need to create an object of that particular method. And a static method call directly by using the class name.
How to use static method :
class_name.static_method_name();
Example –
class Student{
int rollno;
String name;
static void dispaly(){
System.out.println(“Static block Call”);
}
Student(int r, String n){
rollno = r;
name = n;
}
void displayData()
{
System.out.println(rollno+" "+name);
}
public static void main(String args[])
{
Student.display();
Student s1 = new Student9 (111,"Arti");
Student s2 = new Student9 (222,"Harsh");
Student s3 = new Student9 (333,"Aditya");
Student s4 = new Student9 (333,"Vishal");
s1.display();
s2.display();
s3.display();
s4.display();
}
}