Question
Your program uses call stack for methods. For instance, if your program has a main method (all java programs have one!) and it calls a
Your program uses call stack for methods.
For instance, if your program has a main method (all java programs have one!) and it calls a computeArea method, then the call stack will have main first pushed, then computeArea. When your program returns from computeArea, that call information is popped off the call stack. The remaining method call (in this case, main) tells the program where to return. You can think of calling top() or peek() to get the top element of the stack without popping it off the stack.
Running the program see the call stack as the having the following stack methods
push(main)
push(computeArea)
pop(computeArea)
pop(main)
Another example, if your program contains a main method that calls computeBalance which in turn calls computeInterest, the stack would have main, computeBalance, computeInterest. Each would be popped off in turn when the method completes and returns.
Write a small program with 4 methods named method1, method2, method3 and method4. These methods only need to have print statements saying "In method1" and "Exiting method1". (Similar to the first program above) In main, start with a print statement "In main method" then call the various methods in various orders. End your main method with "Exiting main" print statement. Submit your callStackLastName.java and callStackDriverLastName.java with a comment explaining your output.
This is to be written in Java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started