• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Constructor exception doubt

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator






Here I am posting 3 different codes. They all are related to super & sub class exception declaration.

As I conclude from all the code is, "If you are declaring an exception in no-argument super class constructor, you have to declare (not sure same) exception from the every constructor of the sub class."
Please correct me if I am wrong.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sub class Constructor by default calls the super class no-argument constructor. If no-argument constructor of super class is throwing an exception then it must be handled in sub class constructor.Thats the reason we need to add throws clause for no-argument constructor of sub class. But if Sub class Constructor explicitly calls the super class constructor with arguments which is not throwing the exception, then we dont need to handle the exception in subclass.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any bartenders please can explain it?
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy cowboys,

just as nans (by the way, welcome to the Ranch
!! )

said.

This code compiles because the sub class does not call super() but super(int):


Remember that when you put in no constructor at all, a default constructor will be put in:

will not compile, because behind the lines it calls the constructor of the two that does throw an exception:

Do you see know why BadSub does not compile?

Yours,
Bu.
 
I think she's lovely. It's this tiny ad that called her crazy:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic