Solved

Consider a Class That Uses the Following Variables to Implement

Question 8

Multiple Choice

Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
Int top = 0;
A method that implements the String peek() operation can be written as


A) return s[top];
B) if (top == 0.
Throw new RuntimeException("Underflow".;
Else
Return s[top];
C) if (top == 0.
Throw new RuntimeException("Underflow".;
Else
Return s[top-1];
D) return s[top-1];

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions