Java
Consider the following class definition for an array-based stack implementation:pubic class Stack { private int[] m_array; private int m_index; public Stack(int cap) { m_array = new int[cap]; m_index = 0; }
public void push(int v) { if (m_index == m_array.length) throw new RuntimeException("push attempted on a full stack"); else { m_array[m_index] = v; m_index++; } }}
Follow the steps below to create a class SpecialStack with required instance variables and methods.a. Make sure that the SpecialStack classinherits from Stack.b. Declare twoprivate instance variables: a boolean variable m_multiply, and an int variable m_number.c. Create a constructor that takes three parameters: an int cap, a boolean multiply, and an int number.d. The constructor should call the constructor of the super class and initialize the instance variables properly.e. Override the push method so it verifies if m_multiply is true. If so, the method multiplies the parameter v by m_number and then pushes the result onto the stack by calling the push method in the Stack (super) class; otherwise, it pushes v onto the stack without any modification.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here