Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Question from mock site

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sneha,
Could you please mention the mock exam website as im also preparing for the exam.Thanks
 
Sheriff
Posts: 9695
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And quoting the source is also compulsory...
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sneha Kapoor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sagar,
Could you please elaborate. As per Sneha the ans is E. Whether Exception is thrown or Throwable is thrown or Error is thrown?
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mahalakshmi Chandru
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bob...got it
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks everyone...even i understood now clearly :-)
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23926
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sneha Kapoor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Source : http://www.examulator.com/phezam

but not of the today's date.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic