Professional Documents
Culture Documents
CH - 5 User - Defined Methods: Here The Data Type of Variables Mentioned
CH - 5 User - Defined Methods: Here The Data Type of Variables Mentioned
eg- public void sum(int a, int b) here the data type of variables should be mentioned
eg – add (a,b) here the data type of variables should not be mentioned
Return type – it is the data type of the result of a function to be returned to its caller.
Return statement – A statement that sends back the result from a function to its caller
program. It can only return a single value from a method. It is always used at the end of a
method.
Differentiate between -
Scope of a public
Scope of a private Protected method/member
method/member is global. ie, it
method/member is within the can be accessed by inherited
can be accessed from external
class classes only
classes also
Default access specifier Not a default access specifier Not a default access specifier
Primitive data types are passed Reference data types are passed
Note-
import java.util.*;
class fn1
{
public void sum( int a1, int b1)
{ // formal parameters
int c=a1+b1;
System.out.println("Sum = "+c);
}
public static void main (String args[])
{
Scanner in = new Scanner(System.in);
int a, b;
System.out.println("Enter the value of a & b");
a=in.nextInt();
b=in.nextInt();
fn1 ob =new fn1();
ob.sum( a,b); // call by value or pass by value
}
} // actual parameters
Pure function
Impure function
Function Overloading – process of defining functions with the same function names but with
different numbers or types of parameters
Static Binding – finding the best match of the function arguments (types and number of
parameters) on invoking a function is known as early binding or static binding
Recursive function – A function designed in such a way that it calls itself in its body.
_____________________