class Customizedstack
{
private int arr[];//Array to store stack elements
private int top; //acts as a cursor for stack
private int capacity;//maximum size of stack
Customizedstack(int size)//5
{
capacity=size;//5
arr=new int[capacity];//0-4
top=-1;
}
public void push(int value)//10
{
if(top==capacity-1)//4
{
System.out.println(“stack is overflow”);
}
else
{
arr[++top]=value;
}
}
public int sum()
{
int total=0;
for(int i=0; i<=top; i++)
{
total=total+arr[i];
}
return total;
}
}
class Mystacks
{
public static void main(String args[])
{
Customizedstack c=new Customizedstack(5);
c.push(10);
c.push(20);
c.push(30);
int sum=c.sum();
System.out.println(“sum of all the elements of stack=” +sum);
}
}