Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need explaination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need explaination" Watch "Need explaination" New topic

Need explaination

Rajesh k Jha
Ranch Hand

Joined: May 10, 2009
Posts: 72
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

Joined: Aug 03, 2008
Posts: 9465

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??

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

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.

[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
Rajesh k Jha
Ranch Hand

Joined: May 10, 2009
Posts: 72
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

Joined: May 10, 2009
Posts: 72
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:
subject: Need explaination
It's not a secret anymore!