Sometime we write the program and our program grows in size and we want to separate the logic of main method to other method.
Syntax
dataType name()
{
//method body
}
Syntax explation:-
A method is a function written inside a class . since java is an object oriented language, we need to write the method inside same class.
Following method returns multiple of two numbers.
int learner(int a,int b){
int c =a*b;
return c;
}
Calling a method:
A method can be called by creating an object of the class in which the method exists followed by the method call.
Call obj=new Call();→object creation.
obj.learner(a,b);→Method call upon an object.
for ex-Consider the method multiple:
Syntax explation:-
A method is a function written inside a class . since java is an object oriented language, we need to write the method inside same class.
Following method returns multiple of two numbers.
int learner(int a,int b){
int c =a*b;
return c;
}
Calling a method:
A method can be called by creating an object of the class in which the method exists followed by the method call.
Call obj=new Call();→object creation.
obj.learner(a,b);→Method call upon an object.
for ex-Consider the method multiple
int learner(int a, int b)
{
return a*b;
}
//The method is call like this :
call obj=newcall();
c=obj.leraner(1,2)
The values 1 and 2 are copied to a and b and then a*b=1*2=2 is returned in c which is an integer.