Java static code

HI All

I am new to java in below code I am not able to understand the below line of code

 
 Student9.change();  
 

the complete code is mentioned as below

class Student9{  
int rollno;  
String name;  
static String college = "ITS";  
  
static void change(){  
college = "BBDIT";  
 }  
  Student9(int r, String n){  
 rollno = r;  
 name = n;  
 }  
  void display (){System.out.println(rollno+" "+name+" "+college);}  
 public static void main(String args[]){  
Student9.change();  
 Student9 s1 = new Student9 (111,"Karan");  
Student9 s2 = new Student9 (222,"Aryan");  
Student9 s3 = new Student9 (333,"Sonoo");  
 s1.display();  
s2.display();  
s3.display();  
}  
}

In a class, if you declare a method as static, you need not instantiate the class to be able to use the method. So , in your program, the method change() is being called directly by qualifying it with the class name.

You can read more in this link.

1 Like

What bala is saying,

because not only change(), but also college, are static, they are class methods/variables rather than instance (object) methods/variables.

That means "college" will be changed for the entire class, not just for a single instance (object).