Solved

Consider a Class That Uses the Following Variables to Implement

Question 9

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 for adding an item x to the stack can be written as


A) s.add(top,x) ;
B) if (top == s.length.
Throw new RuntimeException("Overflow".;
Else
{
Top ++;
S[top] = x;
}
C) if (top < 0.throw new IndexOutBoundsException(.
S[top] = x;
Top ++;
D) if (top < s.length.
{
S[top] = x;
Top ++;
}
Else
Throw new RuntimeException("Overflow".;

Correct Answer:

verifed

Verified

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

Related Questions