• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt from Abhilash's exam

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I could not get this question right in Abhilash's exam site.Can someone please tell me why the answer is what it is.
Question 36.

public class Base
{
public void aMethod() throws ClassNotFoundException
{
}
}
public class Derived extends Base
{
public void aMethod() throws RuntimeException
{
}
}
Assuming that the classes are in two seperate files, compilation of the Dervied.java causes

1.A compiler error because RuntimeException is not a subclass if ClassNotFoundException.
2.No compiler error.
The answer according to Abhilash is 2.Why?
Waiting for help.
Thanks
Gazala.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
compiles fine because you can throw runtime exceptions not thrown in the overridden class, but you cannot throw checked exceptions in the overridden class.
Bill
 
Gazala Bohra
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill, that was sure a very silly mistake that I made.This will get me no where.Anyways you learn from mistakes!!!
Thanks again,
Gazala.
 
Beauty is in the eye of the tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic