Tutorialslot.com

youtube facebook twitter gmail pinterest

Methods in Java


A method can be defined as a collection of code which is referred to a name and it returns a value as it acts upon a given data.Each method has a unique name.

Initializing methods:
For method declaration it requires the method name,return type,modifiers used and the body of the method.

The general form of method is:
return_type(parameter-list)
{
body of method
}

Example:
public void callSum()
{
int theSum = add(7, 3);
System.out.print("the sum is "+theSum);
}

public int add(int value1, int value2)
{
return value1 + value2;
}

Output:

the sum is 10



Advertisement Powered By Google Adsense






IF YOU LIKE THIS TUTORIALS PLEASE SHARE

Share on whatsapp

POPULAR TAGS

Java java tutorials learn java java programming tutorial learn java online learning java professionals tutorials Multithreading Generics Object Oriented Language Methods Polymorphism Inheritance