// 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
}
}
Hello This is a non static Method
Hello This is a static Method
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
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.
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.