Explanation:
public class Int_List
{
protected int[] list;
protected int numEle = 0;
public Int_List( int size )
{
list = new int[size];
public void add( int value )
{
if ( numEle == list.length )
{
System.out.println( "List is full" );
}
else
{
list[numEle] = value;
numEle++;
}
}
public String toString()
{
String returnStr = "";
for ( int x = 0; x < numEle; x++ )
{
returnStr += x + ": " + list[x] + "\n";
}
return returnStr;
}
}
public class Run_List_Test
{
public static void main( String[] args )
{
Int_List myList = new Int_List( 7 );
myList.add( 102 );
myList.add( 51 );
myList.add( 202 );
myList.add( 27 );
System.out.println( myList );
}
}
Note: Use appropriate keyword when you override "tostring" method