By: Manas Tuwani
METHODS
A group of statements, set of logic which we can reuse for
multiple times is called method.
If any logic is reusable for multiple times, we are identifying
that logic and make it as method or function. Here after
whenever we require that logic, instead of writing that
logic again and again simply we are calling the methods.
There are 2 different methods available in java
1. Static method
2. Non-static method
Static Method
Static methods are creating inside the class and
static methods are loading while class is loading
and we can access these methods directly within
the class, “[Link]” name in different
class and “[Link]” in different
package.
Non-static Methods
Non-static methods also creating inside the
class and these are loading while object is
creating, that’s why non-static methods we can
access only by creating the object.
Note:
In one class we can create any number of methods
(Both Static and Non-Static) but execution starts only
from main method
Static variables we can access into Static and Non
Static methods but we can access Non Static
variables into only Non Static methods
Methods with Arguments/Parameters
Sometimes we need to execute the same methods
multiple times with different data. In that case we are
creating methods with arguments so that while
accessing the methods we can pass the data into
methods through arguments.
Note:
Methods we can create with arguments are either static
or non static methods. Only the way we are calling is
different from Static to Non Static.