Home / Programs / static Method and variable in java, Important Example
🚀 Programming Example

static Method and variable in java, Important Example

👁 1,234 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 Program Code

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

🖥 Program Output

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

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.