Method area:
Method area is the memory where class is loaded along with that static variables and constants are defined.
Stack area:
Stack is a memory area where a method is loaded and its execution takes place.
Write a java program consist of add method to perform addition of two numbers.
- class Addition
- {
- public static void add( ) //Called statement
- {
- int a = 10;
- int b =20;
- int c =a+b;
- System.out.println(c);
- }
- public static void main(String [] args) //Calling statement
- {
- System.out.println("MB");
- add( );
- System.out.println("ME");
- }
- }
Output:
MB
30
30
ME
Types of methods
- No Argument Method.
- Parameterized.
Formal arguments Variables declared inside method.
Actual arguments Data passed inside method calling statement.
Write a java program to perform multiplication of 3 numbers using multiply method.
- class Multiplication
- {
- public static void multiply( int a, int b, int c )
- {
- int d =a*b*c;
- System.out.println(c);
- }
- public static void main(String [] args)
- {
- multiply(2,3,5);
- }
- }
Output:
30
0 Comments