static Method and variable in java, Important Example

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

1129

Program:

 class StudentClass{
     int rollno;
     String name;
     static String subject = "Java Programming Language";

     static void change(){
     subject = "C programming Language";
     }

     StudentClass(int r, String n){
     rollno = r;
     name = n;
     }

     void display (){
		 System.out.println(rollno+" "+name+" "+subject);
		 }

    public static void main(String args[]){

    StudentClass.change();
    StudentClass s1 = new StudentClass (1,"Rahim");
    StudentClass s2 = new StudentClass (2,"Ram");
    StudentClass s3 = new StudentClass (3,"Rocky");

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

Output:

1 Rahim C programming Language
2 Ram C programming Language
3 Rocky C programming Language
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.