DEV Community

Cover image for Static & Non-static methods in java .
bagavath ravichandran
bagavath ravichandran

Posted on

Static & Non-static methods in java .

Today i learned about what are the methods in java,

What is method in java?

 A method in Java is a set of instructions that can be called 
 for execution using the method name.
Enter fullscreen mode Exit fullscreen mode

Image description
PicCourtesy-ScientechEasy

There are mainly two methods in java,
1.Pre-defined methods
2.user-defined methods

1.Predefined Methods:

These are methods that are already available and part of the Java class library. Examples include System.out.println() for printing to the console and Math.sqrt() for calculating square roots.

2.User-defined Methods:

These are methods that you, as the programmer create to perform specific tasks within your program. You define these methods within classes and use them to encapsulate functionality and improve code reusability.

In user-defined methods there are two types in it,

1.Static method
A static method is one that belongs to a class instead of an instance of a class and this method can be called without an instance or the object of the class.

2.Non-static method
non-static methods are methods that are associated with an instance of a class.

Top comments (0)