File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need explaination

 
Rajesh k Jha
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajesh k Jha
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ankit, actually this question is asking "Which inserted independently at the commented line, will produce an exception at the runtime?
choose two answer
 
Rajesh k Jha
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nitish, your explanation is really superb, it really helped me understand the whole concept hidden behind this programme, excellent job man
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic