Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

---IN JAVA-- Your program uses call stack for methods. For instance, if your program has a main method (all java programs have one!) and it

---IN JAVA--

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.

1-push(main)

2-push(computeArea)

3-pop(computeArea)

4-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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

5. Arranging for the training facility and room.

Answered: 1 week ago

Question

1. Discuss the five types of learner outcomes.

Answered: 1 week ago