Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Java Nested Method

PROGRAM:

To show nested methods.
/**
             * @Prof. Jayesh
             * Here we call a method from main().
             * Methods are in same class so known as nested method.

             */


import java.util.Scanner;


public class ExampleOfNestedMethod {

            static int sum()
            {
                        int a,b,c;
                        System.out.println(“Enter the value of a”);
                        Scanner scn=new Scanner(System.in);
                        a=scn.nextInt();
                        System.out.println(“Enter the value of b”);
                        b=scn.nextInt();
                        c=a+b;
                        return c;
            }

            public static void main(String args[])
            {
                        int d=sum();
                        System.out.println(d);
            }
}

OUTPUT:
Enter the value of a
4
Enter the value of b
6
10