Methods -
It is nothing but collection of statements after execution it will return some
output.
syntax-
(access modifier) (method type) (return type) (method name) (argument) {
//body
}
Types of method-
1) main method-
syntax-
public static void main (String[] args) {
//Body
what is use of main method?
Why main method is static method?
2) regular type of method-
1) static method
rule-
a) To execute static method declare we need to call this method inside main method.
we can call static method diretly by its name.
ex-
package methods;
public class Test1 {
//Static method
public static void method1() {
[Link]("Method -Static");
public static void main(String[] args) {
method1();
}
}
b) static method can accept the argument-
ex-
package methods;
public class Test1 {
//Static method
public static void summation(int x, int y) {
int c=x+y;
[Link](c);
public static void main(String[] args) {
summation(50,50);
}
o/p-
100
3) Method can aacept the reurn type-
ex-package methods;
public class Test1 {
//Static method
public static double summation(int x, int y) {
double c=x+y;
return c;
public static void main(String[] args) {
[Link](summation(50,50));
}
----------------------------------------------
2)instance method-