New course! Every coder should learn Generative AI!
Try a free lesson+ 1
can anyone tell me how the return type and function overloading in java done.... i dny knw abt return type pls help
pls help me... thanks in advance
2 Answers
+ 3
a standard method call is this:
<access-modifier> <return-type> methondName(<parameters>){
<code>
}
where <access-modifier> is public, private, protected, etc...
<return-type> is any type; String, int, Boolean, etc...
<parameters> is optional and can be any variable type declared as "<type> variableName" without <> or "".
<code> is whatever you need it to be, variable declarations, other method calls, etc..
lets say we have a method that checks if a number is greater than 10and returns true if it is. we could write aomething like:
public boolean isGreater(int I){
if(I <= 10){
return false;
} else {
return true;
}
}
to use the return type called you would do aeomthing like
boolean test = isGreater( 13 );
and the value returned by the method call would be stored in the variable test.
as far as function overloading concerned I'm pretty aure to has to with many different pareters with the same name but different implementation, the <code> part and different <parameters> in the function call
+ 1
Like @Will said, function overloading means that there are two or more methods with same name but different parameters.