This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

mock question  RSS feed

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
13) public void divide(int a, int b) {
try {
int c = a / b;
}
catch (Exception e) {
System.out.print("Exception ");
} finally {
System.out.println("Finally");
}

Prints out: Finally
Prints out: Exception
Prints out: Exception Finally
No output
ans is Exception finally
can anyone explain me why ans is not finally
Thanks in Advance
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question is incomplete you didn't mention what values of a and b are:

if exception is thrown in try then catch is executed.then finally block will run. otherwise only finally will be printed
[ August 22, 2007: Message edited by: Ameen khan ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ameen khan:
Question is incomplete you didn't mention what values of a and b are:

if exception is thrown in try then catch is executed.then finally block will run. otherwise only finally will be printed

[ August 22, 2007: Message edited by: Ameen khan ]

 
Muthukumar Chellappa
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are not mention which parameters passed to a, b in the method. so it is not possible to say the answer.
one point:
1) Exception arises catch and finally block executed.
2) No Exceptions are arised only finaly block executed
 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably it is a "divide by zero" which throws the exception, so you are getting the output as
Exception
finally
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!