Home / Programs / Static Method and Instance Method in Java
🚀 Programming Example

Static Method and Instance Method in Java

👁 917 Views
💻 Practical Program
📘 Step Learning
static method and instance Method in java

💻 Program Code

// static method and instance Method in java
class MethodExample {
	// this is a instance or non static method
	void sum()
	{
		System.out.println("Hello This is a non static Method");
	}
	
	// this is a static method
	static void add()
	{
		System.out.println("Hello This is a static Method");
	}
	
	
	public static void main(String args[])
	{
	// to access non static	or instance method we have create object
	// we can not access it directly
	MethodExample sahin = new MethodExample();
	sahin.sum(); // access through object
	
	// to access static method we can call it directly
	add();	// access without object
	}

}

                        

🖥 Program Output

Hello This is a non static Method
Hello This is a static Method

                            

📘 Explanation

To access non static or instance method we have create object. We can not access it directly

	MethodExample sahin = new MethodExample();
	sahin.sum(); // access through object

To access static method we can call it directly

	add();	// access without object
📚 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.