// Code to demonstrate the method "call stack" // (not necessarily good style, due to repetition) class DreamCode { public static void main(String[] argh) { call("", "main", "f"); f(); back("", "main", "f"); } public static void f() { call("\t", "f", "g"); g(); back("\t", "f", "g"); } public static void g() { call("\t\t", "g", "h"); h(); back("\t\t", "g", "h"); } public static void h() { System.out.println("\t\t\tFinally entered h."); System.out.println("\t\t\t..."); System.out.println("\t\t\tNow leaving h."); } // ---------------------- utilities public static void call(String prefix, String outer, String inner) { System.out.println(prefix + outer + " calls " + inner + " ..."); } public static void back(String prefix, String outer, String inner) { System.out.println(prefix + "... back to " + outer + " (returned from " + inner + ")."); } }