aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from mock site Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from mock site" Watch "Question from mock site" New topic
Author

Question from mock site

Sneha Kapoor
Ranch Hand

Joined: Jun 08, 2009
Posts: 49
11. static void test() throws Error {

12. if (true) throw new AssertionError();

13. System.out.print(”test “);

14. }

15. public static void main(String[] args) {

16. try { test(); }

17. catch (Exception ex) { System.out.print(”exception “); }

18. System.out.print(”elld “);

19. }

What is the result?

A. end

B. Compilation fails.

C. exception end

D. exception test end

E. A Throwable is thrown by main.

F. An Exception is thrown by main



What will be the answer and why


Mahalakshmi Chandru
Ranch Hand

Joined: Feb 26, 2009
Posts: 48
Sneha,
Could you please mention the mock exam website as im also preparing for the exam.Thanks
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

And quoting the source is also compulsory...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Sneha Kapoor wrote:
What will be the answer and why

Why don't you tell us the answer and why ? and If you felt its not the way you thought, then we can help you to solve your doubt ?

And please UseCodeTags

By the way, Welcome to JR


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sneha Kapoor
Ranch Hand

Joined: Jun 08, 2009
Posts: 49
I thought answer is F but in the site it is mentioned E.

BTW source is : A question a day,i save all question so i picked up from that list while i was solving them.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I think, for this question, onc need to good at Throwable or Exception handling classes hierarchy. Here, "Error" is thrown which is subclass of "Throwable" and "Exception" is subclass of "Throwbale" but it is NOT "Error", that's why answer is E .

[Edited typo ]
Mahalakshmi Chandru
Ranch Hand

Joined: Feb 26, 2009
Posts: 48
Sagar,
Could you please elaborate. As per Sneha the ans is E. Whether Exception is thrown or Throwable is thrown or Error is thrown?
Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
Edit: I AM SO SLOW

Ankit Garg wrote:And quoting the source is also compulsory...

To remind you. To work with your code, one has to copy it AND delete the numbers AND replace the quotes.


Sneha Kapoor wrote:I thought answer is F but in the site it is mentioned E.

For your question. An AssertionError is an Error, which is a Throwable.

cheers
Bob


SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Mahalakshmi Chandru
Ranch Hand

Joined: Feb 26, 2009
Posts: 48
Thanks Bob...got it
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Mahalakshmi Chandru wrote:Sagar,
Could you please elaborate. As per Sneha the ans is E. Whether Exception is thrown or Throwable is thrown or Error is thrown?

Sorry, I corrected my mistake in original post, its typo. Between, I thought the last two option is pretty much confusing and not direct, its casting involved if you know this hierarchy.

Mahalakshmi Chandru
Ranch Hand

Joined: Feb 26, 2009
Posts: 48
Sagar,
Its casting from Error to throwable. If there was an option saying 'An Error is thrown' then we would have chosen that.
Sneha Kapoor
Ranch Hand

Joined: Jun 08, 2009
Posts: 49
thanks everyone...even i understood now clearly :-)
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Mahalakshmi Chandru wrote:Sagar,
Its casting from Error to throwable. If there was an option saying 'An Error is thrown' then we would have chosen that.

Right, Its like this AssertionError -> Error -> Exception.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Sneha,

Quoting your sources is required on JavaRanch - when you copy a question from a book, mock exam or other source, you must tell us where you copied it from. If you don't quote your sources, your question will be deleted, and if you repeatedly do not quote your sources, your account might even be locked by the administrators.

Please tell us exactly where you copied the above question from.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Sneha Kapoor wrote:
BTW source is : A question a day,i save all question so i picked up from that list while i was solving them.


Using google, I am assuming you mean examulator? BTW, there are a ridiculous number of Java sources, many from blogs, and many that are not allowed on the Ranch.

Please help us as much as possible, by being as clear as possible -- as what may seem obvious to you (because you use the source) may not be as obvious to us.

Thanks,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sneha Kapoor
Ranch Hand

Joined: Jun 08, 2009
Posts: 49
Source : http://www.examulator.com/phezam

but not of the today's date.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from mock site