# Java static code

**URL:** <https://community.unix.com/t/java-static-code/371257>\
**Category:** Programming\
**Created:** [March 8, 2018, 8:56am UTC](https://community.unix.com/t/java-static-code/371257 "2018-03-08T08:56:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scriptor](https://community.unix.com/letter_avatar/scriptor/32/6_22734026db12803ebb3e059622ac3534.png) [@scriptor](https://community.unix.com/u/scriptor)\
**Post date:** [March 8, 2018, 8:56am UTC](https://community.unix.com/t/java-static-code/371257/1 "2018-03-08T08:56:05Z")

</div>

HI All

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

```nohighlight
 
 Student9.change();  
 

```

the complete code is mentioned as below

```nohighlight
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();  
}  
}

```

---

<div class="post-metadata">

**Author:** ![balajesuri](https://community.unix.com/user_avatar/community.unix.com/balajesuri/32/1423_2.png) [@balajesuri](https://community.unix.com/u/balajesuri)\
**Post date:** [March 8, 2018, 11:52pm UTC](https://community.unix.com/t/java-static-code/371257/2 "2018-03-08T23:52:55Z")

</div>

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](https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html).

---

<div class="post-metadata">

**Author:** ![dryden](https://community.unix.com/user_avatar/community.unix.com/dryden/32/9996_2.png) [@dryden](https://community.unix.com/u/dryden)\
**Post date:** [April 22, 2018, 5:59am UTC](https://community.unix.com/t/java-static-code/371257/3 "2018-04-22T05:59:23Z")

</div>

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).
