静态行为如何变化?

时间:2014-05-23 19:19:10

标签: java static

我搜索了论坛,发现了静态变量和普通变量的各种选项。但我仍然无法弄清楚: -

当我执行下面给出的这个程序时,我得到了所需的输出,但是如果我删除了"静态"在String大学前面的关键词,它也给了我相同的输出。

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

那么使用static关键字是什么?

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 个答案:

没有答案