Article View: comp.lang.java.help
Article #153Help -- Java Error
From: Shashank
Date: Sun, 08 Aug 1999 00:00
Date: Sun, 08 Aug 1999 00:00
50 lines
1478 bytes
1478 bytes
Consider the following Java Program
class A
int id;
A()
id = 1;
}
A(int i)
id = i;
}
public int id()
return id;
}
}
class B extends A
B(int i)
}
}
public class FinalC
public static void main(String[] args)
A[] array = new B[5];
array[0] = new B(10);
array[1] = new B(8);
array[2] = new B(6);
array[3] = new A(4); // line 23
array[4] = new A(2); // line 24
for(int i = 0; i< 5; i++)
System.out.println(array[i].id());
}
}
}
The execution returns the exception:
java.lang.ArrayStoreException:
at FinalC.main(FinalC.java:23)
Why the program runs in this way.
What Changes should I make to the instructions on lines 23 and 24 to correct
the problem.
Technical Details
Message-ID:
<7olh27$sb$1@news.chorus.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10568c,fe1ae2c02024cf32,start X-Google-Attributes: gid10568c,public X-Google-Thread: 113ae9,fe1ae2c02024cf32,start X-Google-Attributes: gid113ae9,public X-Google-Thread: fb99b,fe1ae2c02024cf32,start X-Google-Attributes: gidfb99b,public From: "Shashank" <sowshank@itis.com> Subject: Help -- Java Error Date: 1999/08/08 Message-ID: <7olh27$sb$1@news.chorus.net> X-Deja-AN: 510461162 Organization: IntraNet Inc: Madison, Wisconsin's ISP X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: comp.lang.java.help,cz.comp.lang.java,de.comp.lang.java