0% found this document useful (0 votes)
5 views3 pages

Java Method Types and Syntax Guide

The document explains the concept of methods in programming, detailing their syntax and types. It covers the main method, static methods, and instance methods, providing examples of how to declare and use them. Additionally, it discusses the rules for executing static methods and their ability to accept arguments and return values.

Uploaded by

Akshay Khot
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Java Method Types and Syntax Guide

The document explains the concept of methods in programming, detailing their syntax and types. It covers the main method, static methods, and instance methods, providing examples of how to declare and use them. Additionally, it discusses the rules for executing static methods and their ability to accept arguments and return values.

Uploaded by

Akshay Khot
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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-

You might also like