0% found this document useful (0 votes)
3 views

Methods in Java Session 22

Methods in Java are reusable blocks of code that can be called multiple times, categorized into static and non-static methods. Static methods are loaded with the class and can be accessed directly, while non-static methods require an object for access. Additionally, methods can accept arguments to execute with different data, and both types of methods can be defined with or without parameters.

Uploaded by

ashutosh pandey
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Methods in Java Session 22

Methods in Java are reusable blocks of code that can be called multiple times, categorized into static and non-static methods. Static methods are loaded with the class and can be accessed directly, while non-static methods require an object for access. Additionally, methods can accept arguments to execute with different data, and both types of methods can be defined with or without parameters.

Uploaded by

ashutosh pandey
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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, “classname.method” name in different
class and “classname.methodname” 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.

You might also like