aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes [Java Programmer Certification Mock Exam   (Dan Chisholm) wrong solution.. 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 "[Java Programmer Certification Mock Exam   (Dan Chisholm) wrong solution.." Watch "[Java Programmer Certification Mock Exam   (Dan Chisholm) wrong solution.." New topic
Author

[Java Programmer Certification Mock Exam (Dan Chisholm) wrong solution..

avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453



i think the answer should be e . line no 2 marked in the question will never throw exception because we are not trying to use the reference variable "sub". but the answer given in the book is "d".[Java Programmer Certification Mock Exam
(Dan Chisholm)]
is it correct sir??


SCJP 5.0 SCWCD 5.0
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
What happened when you compiled and ran the code?


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823


Exception in thread "main" java.lang.ClassCastException: Base cannot be cast to Sub
at Orange.main(Orange.java:10)



It is a compile time error as the object of the super type cannot to cast to its subtype. Yes you are correct as far as I think.


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42600
    
  65
sudipto shekhar wrote:

Exception in thread "main" java.lang.ClassCastException: Base cannot be cast to Sub

It is a compile time error as the object of the super type cannot to cast to its subtype. Yes you are correct as far as I think.

What you posted is a runtime error, not a compile time error. But either way, "e" -which the first post suggested- is not correct.


Ping & DNS - my free Android networking tools app
Chaitanya Jadhav
Ranch Hand

Joined: Mar 13, 2009
Posts: 41

NOT wrong solution.

the option d is right.(RuntimeException at line number 2)



SCJP 1.5 80%
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

thanks alot everyone..i got the point..i was a bit wrong.
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Sorry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Java Programmer Certification Mock Exam (Dan Chisholm) wrong solution..