This question is from ExamLab6.0 Mock test.
Here i m confused with the answer that is given, answer says that A and B is the right answer, but i m not sure how B is the correct answer, can
somebody explain the concept behind this?
A) A[1]=new A();
B) a[0]=new B();
C) a[0]=new C();
D) a[0]=new D();
E) a[0]=new Object();
F) Existing code gives a compile time error.
G) Existing code gives a runtime exception.
What does the question says about the options?? Does it says that which of these will compile fine or which will compile and run fine or something else??
A will give a Array indexoutofbound exception And B will give an Arraystoreexception because the array object is supposed to store c and its subclass objects and B is not a subclass of C. I suppose this question only asks for exceptions. If its not then E will give a compile time error. Because Object is not a A. A is-a Object. For compilation this relationship should be passed with the reference variable type.
Hello Ankit, actually this question is asking "Which inserted independently at the commented line, will produce an exception at the runtime?
choose two answer