0

I have searched the forum and found various options for Static and normal variable. But i am still not able to figure out this: -

When i am executing this program given below, i am getting the desired output, but if i delete the "static" key word which is in front of String college, it also gives me the same output.

 static String college ="ITS"; // Same output
 String college ="ITS";// Same output

So whats the use of using the static keyword??

class Student{  
   int rollno;  
   String name;  
      static String college ="ITS";  


Student(int r,String n){  
   rollno = r;  
   name = n;  
   }  
 void display (){System.out.println(rollno+" "+name+" "+college);}  

 public static void main(String args[]){  
 Student s1 = new Student (111,"Karan");  
 Student s2 = new Student (222,"Aryan");  

 s1.display();  
 s2.display();  
 }  
}

0 Answers0