02_Intro-to-Functions_and_static-Functions
02_Intro-to-Functions_and_static-Functions
2
class School
{
public static void main(String args[ ])
{
int x = 7, y = 5, z = 4 ;
double a;
School ob = new School( ) ;
a = ob.avg(x, y, z) ; Method Calling or Invocation
System.out.println(" Average = " + a) ;
}
7 5 4 Call-by-Value
public double avg(int n1, int n2, int n3)
{
double rs ;
rs = (n1 + n2 + n3) / 3.0 ;
return rs ;
}
}}
x n1
y Actual Arguments n2 Formal Parameters
z n3
3
Access-Specifier Return-Type Method-Name
4
class Box
{
public static void main(String args[ ])
{
double L = 7.5, B = 5.0, H = 2.5 ;
double v;
Box ob = new Box( ) ;
v = ob.vol(L, B, H) ; Method Calling or Invocation
System.out.println(" Vol. of the box = " + v) ;
}
Call-by-Value
7.5 5.0 2.5
public double vol(double L1, double B1, double H1)
{
double rs ;
rs = L1 * B1 * H1 ;
return rs ;
}
}}
The Actual Arguments are : ………………………………..
The Formal Parameters are : ………………………………
5
6
7
8
import java.util.* ;
rs = ob.fact(num) ;
System.out.println("Factorial of the input number = " + rs) ;
}
}
10
class School
{
public static void main(String args[ ])
{
long p = 500000 ;
int t = 3 ;
double r = 7.1 ;
double I ;
i = SI ( p, t, r ) ;
System.out.println(" Simple Intt. = " + i ) ;
}
}}
11
Method Signature and Method Header
Method Header
12