I am in a beginner's Java class. I only know basic Java. We just started polymorphism and Inheritance. My problem is placing objects into an array. I have an array of ten Runner
objects as follows.
import java.util.*;
public class Race
{
public static void main(String []args)
{
Runner r1 = new Runner("Jack Sprat", 10);
Runner r2 = new Runner("Cecil Litwack", 8);
Runner r3 = new Runner("Dina Might", 3);
Runner r4 = new Runner("Seymour Butts", 4);
Runner r5 = new Runner("Ima reject", 1 );
Runner r6 = new Runner("Ivan Earache", 9);
Runner r7 = new Runner("Ace Ventura", 6);
Runner r8 = new Runner("Joan O'Farc", 7);
Runner r9 = new Runner("Jack O'Lantern", 5);
Runner r10 = new Runner("Jim Nasium", 2);
Runner[] raceArray = new Runner[10];
raceArray[0] = r1;
raceArray[1] = r2;
raceArray[2] = r3;
raceArray[3] = r4;
raceArray[4] = r5;
raceArray[5] = r6;
raceArray[6] = r7;
raceArray[7] = r8;
raceArray[8] = r9;
raceArray[9] = r10;
Let's say I want to place the object at index 1
into index 0
, will the object at index 0
go to index 1
? Or will the object at index 0
be removed from the array? If it is removed how do I make it to when I place an object at a different array index the objects just trade places in the array?