Question
Stack heap questions
5. (16 points) (either 2 or 4 points each, look below for individual section points) Answer some questions about the following Java program; use the line numbers to identify particular state ments or variables. Assume that Widget is a valid class defined in some other file. 1 public class Midi ( 2 public int p, q: // instance variables 3 4 public void funci(int x, int y) ( 5 int p,q 6 7 String S; p=3*25 + x; 9 10 11 public int func20 t 12 p=50; 13 14 Widget w = new Widget(); q = 100; 15 func1 (p.g) w=new Widget(); return 3141; 16 17 18 19 (a) (2 points) Identify a statement where an optimization is likely to occur during the com- pilation process (b) (2 points) Identify an example of a name binding that has a hole in its scope.
media%2Fd4c%2Fd4cd5899-abf7-4bd4-bf47-cb
0 0
Add a comment Improve this question Transcribed image text
Answer #1

a. line no 14 : Widget w = new Widget();

line no 16 : w = new Widget();

both of the statement will be optimized at compilation Time because there is no change in the first object at line no 14

so the compiler will not assign two different object

b. In func1() variable p and q are initialized again hence it will be treated as the local variable of func1 only, the change in these variables will not affect the value of the instance variable.

c. when func2() is calling func1() then there will be new stack allocation for the func1() to store the variable of func1() which will available to only func1() scope.

d. Widget w = new Widget() it will be allocated in the heap

again in line 16 w= new Widget() it will again point to the same heap location.

e. funct1() stack frame will store

p,q,x,y and s along with the instance of the Calling function

f. func2() stack frame will store

w and instance of func1() called function

Add a comment
Know the answer?
Add Answer to:
Stack heap questions 5. (16 points) (either 2 or 4 points each, look below for individual...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part Two: Fill in the Blanks and True/False (24 total points - 2 points each) For...

    Part Two: Fill in the Blanks and True/False (24 total points - 2 points each) For each of the following, fill in the most appropriate word(s)phrase/solution in each blank 1) Keywords, identifiers and literals are all kinds of are simply groups of characters that are used for various purposes in a program. , which 2) The Java expression: 11 - 2 + 3 evaluates to 3) List the Java boolean (logical) operators in order from highest priority to lowest priority...

  • Question 2 [5 points) State if each of the below statements is True or False 1...

    Question 2 [5 points) State if each of the below statements is True or False 1 2 3 The Compiler skips comments. A function can return a value of type array. An array index starts with 1. Pass by value is the default in CH, except when passing arrays as arguments to function The default storage class for local variables is static. A pointer provides an indirect means of accessing the value of a particular data item The logical operators...

  • Please help me to answer the 5 programming questions and give some specific explanations, thanks a...

    Please help me to answer the 5 programming questions and give some specific explanations, thanks a lot !!! Question Consider a class hierarchy that includes a class called Creature, with subclasses called Unicorn and Dragon. The Creature class has a method called feelsLike, Not yet answered which is overridden in the Unicorn and Dragon class. Marked out of The feelsLike method of the Creature class returns "smooth", while the feelsLike method is overridden in the Unicorn class to return "fluffy"...

  • Write in JAVA Get Familiar with the Problem Carefully read the program description and look at...

    Write in JAVA Get Familiar with the Problem Carefully read the program description and look at the data file to gain an understanding of what is to be done. Make sure you are clear on what is to be calculated and how. That is, study the file and program description and ponder! Think! The Storm Class Type Now concentrate on the Storm class that we define to hold the summary information for one storm. First, look at the definition of...

  • ------------------------------------------------------------------------------------------------------------ CODE ALREADY HAVE BELOW--------------------------------------------------------------------------------------- public class LinkedQueue<T>

    ------------------------------------------------------------------------------------------------------------ CODE ALREADY HAVE BELOW--------------------------------------------------------------------------------------- public class LinkedQueue<T> implements QueueADT<T> {    private int count;    private LinearNode<T> head;    private LinearNode<T> tail;               public LinkedQueue()    {        count = 0;        head = null;        tail = null;    }    @Override    public void enqueue(T element)    {        LinearNode<T> node = new LinearNode<T> (element);        if(isEmpty())            head = node;        else           ...

  • Q22 Consider the following 2 text files and Java program. 8 Points Answer the following questions...

    Q22 Consider the following 2 text files and Java program. 8 Points Answer the following questions keeping in mind that: • All three files are in the same directory, and there are no other files. • The program may crash. If the program crashes, answer the question with: "The program crashes" standings1.txt: 1 Valtteri Bottas 25 2 Charles Leclerc 18 3 Lando Norris 16 4 Lewis Hamilton 12 standings2.txt: 1 Valtteri Bottas 43 2 Lewis Hamilton 37 3 Lando Norris...

  • Please help with my car traffic simulator! Code that I already have below, I do not know how to...

    Please help with my car traffic simulator! Code that I already have below, I do not know how to start it off! public class IntersectionSimulation { private final static int EAST_WEST_GREEN_TIME = 30 ; private final static int[] NORTH_SOUTH_GREEN_TIMES = { 20, 24, 30, 42 } ; private final static int[] CAR_INTERSECTION_RATES = { 3, 5, 10 } ; private final static int[] CAR_QUEUEING_RATES = { 5, 10, 30 } ; private final static int[] EXPERIMENT_DURATIONS = { 3*60, 5*60,...

  • True False Question 2 (3 points) Given a singly linked list with more than two nodes,...

    True False Question 2 (3 points) Given a singly linked list with more than two nodes, to remove the second node from a linked list with only head reference, assume curr - head, next, you do Set curr.next to head.next Oset head. next to curr.next Set head, next to curr Oset head to curr.next TL th Question 3 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the last...

  • I have updated my previously posted C++ question to ensure that I have included all of...

    I have updated my previously posted C++ question to ensure that I have included all of the necessary documentation in order to complete Part 2 - Bank Account of the assigned lab in its entirety. Please note that the lab below is somewhat lengthy, and I do not expect you to answer each question! If coding the full lab is too much to ask, please focus soley on Part 2 of the lab, titled Bank Account and the subsections that...

  • This task involves constructing a Java program that supports interaction via a graphical user interface.The object...

    This task involves constructing a Java program that supports interaction via a graphical user interface.The object is to implement a Scrabble graphical game. The basis for the game is quite simple. Presented with a 6x6 grid of Scrabble tiles, the challenge is for the player(s) to form as many high scoring words as possible.  Words may only be formed from sequences of adjacent tiles.  Two tiles are adjacent if their edges or corners meet.  A tile may...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT