Which code segment should you use?

You are creating an undo buffer that stores data modifications.
You need to ensure that the undo functionality undoes the most recent data modifications first.
You also need to ensure that the undo buffer permits the storage of strings only.
Which code segment should you use?

You are creating an undo buffer that stores data modifications.
You need to ensure that the undo functionality undoes the most recent data modifications first.
You also need to ensure that the undo buffer permits the storage of strings only.
Which code segment should you use?

A.
Stack undoBuffer = new Stack();

B.
Stack undoBuffer = new Stack();

C.
Queue undoBuffer = new Queue();

D.
Queue undoBuffer = new Queue();

Explanation:
A Stack caters for a last in first out scenario similar to what is required in an undo buffer. By using Generics you can force a strongly typed collection that takes strings only.
B is not strongly typed for strings, it will take any type of object. C & D Queue is a First in First out collection, it is not appropriate in this instance.



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Lisa

Lisa

Answer A and B are the same.
Answer C and D are the same.

seenagape

seenagape

I have the same idea. A