Forums Register Login

Need explaination

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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??
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Hello Ankit, actually this question is asking "Which inserted independently at the commented line, will produce an exception at the runtime?
choose two answer
+Pie Number of slices to send: Send
Thanks Nitish, your explanation is really superb, it really helped me understand the whole concept hidden behind this programme, excellent job man
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 709 times.
Similar Threads
regarding overloading-Dan Chisholm's Mock Exam question
Throwing an Exception
Another examLab casting question
Question from khalids sample paper
Final Class cannot be instantiated
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:47:58.