Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question from mock site

 
Sneha Kapoor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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


 
Mahalakshmi Chandru
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sneha,
Could you please mention the mock exam website as im also preparing for the exam.Thanks
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And quoting the source is also compulsory...
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Bob...got it
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
thanks everyone...even i understood now clearly :-)
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 21193
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Source : http://www.examulator.com/phezam

but not of the today's date.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic