Java Program to Show the Nesting of Methods

This is a Java Program to Show the Nesting of Methods. When a method in java calls another method in the same class, it is called Nesting of methods.

Enter length, breadth and height as input. After that we first call the volume method. From volume method we call area method and from area method we call perimeter method. Hence we get perimeter, area and volume of cuboid as output.

Here is the source code of the Java Program to Show the Nesting of Methods. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. import java.util.Scanner;
  2. public class Nesting_Methods 
  3. {
  4.     int perimeter(int l, int b)
  5.     {
  6.             int pr = 12 * (l + b);
  7.             return pr;
  8.     }
  9.     int area(int l, int b)
  10.     {
  11.             int pr = perimeter(l, b);
  12.             System.out.println("Perimeter:"+pr);
  13.             int ar = 6 * l * b;
  14.             return ar;
  15.     }
  16.     int volume(int l, int b, int h)
  17.     {
  18.         int ar = area(l, b);
  19.         System.out.println("Area:"+ar);
  20.         int vol ;
  21.         vol = l * b * h;
  22.         return vol;
  23.     }
  24.     public static void main(String[] args) 
  25.     {
  26.         Scanner s = new Scanner(;
  27.         System.out.print("Enter length of cuboid:");
  28.         int l = s.nextInt();
  29.         System.out.print("Enter breadth of cuboid:");
  30.         int b = s.nextInt();
  31.         System.out.print("Enter height of cuboid:");
  32.         int h = s.nextInt();
  33.         Nesting_Methods obj = new Nesting_Methods();
  34.         int vol = obj.volume(l, b, h);
  35.         System.out.println("Volume:"+vol);
  36.     }
  37. }


$ javac
$ java Nesting_Methods
Enter length of cuboid:5
Enter breadth of cuboid:6
Enter height of cuboid:7

Sanfoundry Global Education & Learning Series – 1000 Java Programs.


Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.