Java is one programming languages. In this language, java introduces different methods in programs. Like abstract method, final method, static method, synchronized method etc.
In this blog we will understand basic different of static and non-static method.
We already see main class static methods concepts in our past blogs. Now we see other class static method how to access by main class.
Different between static and non-static methods in java programs
– Static methods directly call by class name, non-static method needs object for access.
Let’s see example on static and non-static methods in java programs.
// Two Method
// 1. Static
static void method1()
System.out.println(“Welcome in Static Methods”);
// 2. Non-Static
System.out.println(“Welcome in Non-Static Methods”);
public static void main(String args)
// How to call static Methods from other class
A.method1(); // No Need to create an object for static methods
// How to call non-static Methods from other class
// We need object
A a1 = new A(); // a1 is an object
a1.method2(); // call to non-static methods
Welcome in Static Methods
Welcome in Non-Static Methods
Video available on YouTube.
If you have query about this blog, you can directly post comment or subscribe on website.
Share and Enjoy
116total visits,1visits today