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.

  1. class Addition
  2. {  
  3. public static void add( )                                                   //Called statement
  4. {
  5. int a = 10;
  6. int b =20;
  7. int c =a+b;
  8. System.out.println(c);
  9. }
  10. public static void main(String [] args)                           //Calling statement
  11. {
  12. System.out.println("MB");
  13. add( );
  14. System.out.println("ME");
  15. }

Output:

MB                                                        
30                                                          
ME                                                        
                                                              
                                                              
                                                              



Types of methods
  1. No Argument Method.
  2. Parameterized. 

No Argument Method

Parameterized Method

Definitiion: The method which does not have any formal arguments

Definitiion: The methods which has formal arguments

Program: 

          public static void add( )

           {

              int a = 3;

              int b = 2;

              Int c = a+b;

              System.out.println(c);

           }

Program:

              public static void add(int a, int b )

           {

              Int c = a+b;

              System.out.println(c);

           }

Output: 

               50

Output: 

  1. add(10,20)     //30

  2. add(2,3)         //5

  3. add(-4,5)       //1



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.

  1. class Multiplication
  2. {  
  3. public static void multiply( int a, int b, int c )                                                  
  4. {
  5. int d =a*b*c;
  6. System.out.println(c);
  7. }
  8. public static void main(String [] args)                          
  9. {
  10. multiply(2,3,5);
  11. }

Output:

30